Petr
Petr

Reputation: 14505

how can I simply benchmark my linux application

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...

Upvotes: 3

Views: 2585

Answers (2)

Fred Foo
Fred Foo

Reputation: 363817

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.

Upvotes: 4

Jonathan Hall
Jonathan Hall

Reputation: 79774

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.

Upvotes: 0

Related Questions