2

Imagine you write application, alternative to some existing version and you want to compare if it's more effective or not,

you can simply use time like

time yourcommand
time oldcommand

and compare the execution time to check some difference, but this isn't very detailed

Is there similar command to check more data? Such as memory usage, cpu utilization, cpu peak, memory peak etc...

2
  • 1
    What language ? Your after a profiler. Strace can give some food info in general but your after a dedicated profile
    – exussum
    Jun 22, 2013 at 18:44
  • in this case it's c++ vs c,but I was looking rather for some simple command that do these basic, but most important measurements, which answer bellow perfectly covers
    – Petr
    Jun 22, 2013 at 19:05

2 Answers 2

3

A good implementation of time actually tells you a lot more than wallclock time. Most Linux systems have one, but Bash tends to obscure it in favor of its built-in time, so you have to call it as /usr/bin/time:

$ /usr/bin/time python -c "import numpy as np; np.empty(100000)"
0.12user 0.00system 0:00.13elapsed 96%CPU (0avgtext+0avgdata 12860maxresident)k
0inputs+0outputs (0major+3777minor)pagefaults 0swaps

That's CPU use, memory usage and several other statistics for a simple Python command. See the manpage time(1) for what time can do.

1
  • For memory usage, consider also using pmap or simply cat /proc/$(pidof yourcommand)/maps during execution of your benchmark. Jun 22, 2013 at 19:46
0

There is no single best way to do what you're talking about, as it depends a lot on your application, as well as what you wish to profile.

But this post offers some suggestions on ways to profile Linux or a specific application, which may help you along the right direction.

You will likely find better answers if you can tell us more specifically what you're hoping to profile, which language(s) you're using, etc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.