Properly measure execution time for benchmarking
up vote
0
down vote
favorite
I hope this is the correct place to ask this question.
I would like to benchmark a program using some test instances. I’m primarily interested in the cpu time the program took to execute and to this end, I’ve found the time command that gives me the real, user and sys time. As I’m quite new to linux, I’m not sure which of these to take. For me, user and sys seem to be my best bet, but I’m not quite sure which one to take. Does it make sense to add them up to get the total cpu-seconds or is user the most meaningful in my application?
Any help appreciated!
command-line 18.04 performance
New contributor
Gorid is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
up vote
0
down vote
favorite
I hope this is the correct place to ask this question.
I would like to benchmark a program using some test instances. I’m primarily interested in the cpu time the program took to execute and to this end, I’ve found the time command that gives me the real, user and sys time. As I’m quite new to linux, I’m not sure which of these to take. For me, user and sys seem to be my best bet, but I’m not quite sure which one to take. Does it make sense to add them up to get the total cpu-seconds or is user the most meaningful in my application?
Any help appreciated!
command-line 18.04 performance
New contributor
Gorid is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
time sleep 10
– j-money
21 hours ago
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I hope this is the correct place to ask this question.
I would like to benchmark a program using some test instances. I’m primarily interested in the cpu time the program took to execute and to this end, I’ve found the time command that gives me the real, user and sys time. As I’m quite new to linux, I’m not sure which of these to take. For me, user and sys seem to be my best bet, but I’m not quite sure which one to take. Does it make sense to add them up to get the total cpu-seconds or is user the most meaningful in my application?
Any help appreciated!
command-line 18.04 performance
New contributor
Gorid is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
I hope this is the correct place to ask this question.
I would like to benchmark a program using some test instances. I’m primarily interested in the cpu time the program took to execute and to this end, I’ve found the time command that gives me the real, user and sys time. As I’m quite new to linux, I’m not sure which of these to take. For me, user and sys seem to be my best bet, but I’m not quite sure which one to take. Does it make sense to add them up to get the total cpu-seconds or is user the most meaningful in my application?
Any help appreciated!
command-line 18.04 performance
command-line 18.04 performance
New contributor
Gorid is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Gorid is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited 9 hours ago
dessert
20.9k55896
20.9k55896
New contributor
Gorid is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked 21 hours ago
Gorid
1
1
New contributor
Gorid is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Gorid is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Gorid is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
time sleep 10
– j-money
21 hours ago
add a comment |
time sleep 10
– j-money
21 hours ago
time sleep 10– j-money
21 hours ago
time sleep 10– j-money
21 hours ago
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
By default, there are two time commands on your system:
- a
bashshell keyword
This is called when you runtime, you can get help about it withhelp time. If you want to tweak its output, read about theTIMEFORMATvariable inman bash. - a binary
/usr/bin/time
If you want this you need to call it with its full path, you can get help about it withman time.
The /usr/bin/time binary comes with a nice -f, --format option which lets you choose the information in its output. The mentioned manpage has the full list of specifiers under FORMATTING THE OUTPUT, here are just some suggestions that may be relevant for you:
K Average total (data+stack+text) memory use of the process, in Kilobytes.
S Total number of CPU-seconds used by the system on behalf of the process (in kernel mode), in seconds.
U Total number of CPU-seconds that the process used directly (in user mode), in seconds.
If S and U is what’s important in your case and you want those two on separate lines, your command line could look like this:
/usr/bin/time -f "%Sn%U" /path/to/program
As S and U are available for bash’s time as well, this translates to:
TIMEFORMAT=$'%Sn%U' && time /path/to/program
It’s worth noting that the bash keyword is able to output milliseconds while the binary does only output centiseconds. The keyword may also be faster, as no external program needs to be called.
For an overview on the timing topic, I recommend reading man 7 time.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
By default, there are two time commands on your system:
- a
bashshell keyword
This is called when you runtime, you can get help about it withhelp time. If you want to tweak its output, read about theTIMEFORMATvariable inman bash. - a binary
/usr/bin/time
If you want this you need to call it with its full path, you can get help about it withman time.
The /usr/bin/time binary comes with a nice -f, --format option which lets you choose the information in its output. The mentioned manpage has the full list of specifiers under FORMATTING THE OUTPUT, here are just some suggestions that may be relevant for you:
K Average total (data+stack+text) memory use of the process, in Kilobytes.
S Total number of CPU-seconds used by the system on behalf of the process (in kernel mode), in seconds.
U Total number of CPU-seconds that the process used directly (in user mode), in seconds.
If S and U is what’s important in your case and you want those two on separate lines, your command line could look like this:
/usr/bin/time -f "%Sn%U" /path/to/program
As S and U are available for bash’s time as well, this translates to:
TIMEFORMAT=$'%Sn%U' && time /path/to/program
It’s worth noting that the bash keyword is able to output milliseconds while the binary does only output centiseconds. The keyword may also be faster, as no external program needs to be called.
For an overview on the timing topic, I recommend reading man 7 time.
add a comment |
up vote
0
down vote
By default, there are two time commands on your system:
- a
bashshell keyword
This is called when you runtime, you can get help about it withhelp time. If you want to tweak its output, read about theTIMEFORMATvariable inman bash. - a binary
/usr/bin/time
If you want this you need to call it with its full path, you can get help about it withman time.
The /usr/bin/time binary comes with a nice -f, --format option which lets you choose the information in its output. The mentioned manpage has the full list of specifiers under FORMATTING THE OUTPUT, here are just some suggestions that may be relevant for you:
K Average total (data+stack+text) memory use of the process, in Kilobytes.
S Total number of CPU-seconds used by the system on behalf of the process (in kernel mode), in seconds.
U Total number of CPU-seconds that the process used directly (in user mode), in seconds.
If S and U is what’s important in your case and you want those two on separate lines, your command line could look like this:
/usr/bin/time -f "%Sn%U" /path/to/program
As S and U are available for bash’s time as well, this translates to:
TIMEFORMAT=$'%Sn%U' && time /path/to/program
It’s worth noting that the bash keyword is able to output milliseconds while the binary does only output centiseconds. The keyword may also be faster, as no external program needs to be called.
For an overview on the timing topic, I recommend reading man 7 time.
add a comment |
up vote
0
down vote
up vote
0
down vote
By default, there are two time commands on your system:
- a
bashshell keyword
This is called when you runtime, you can get help about it withhelp time. If you want to tweak its output, read about theTIMEFORMATvariable inman bash. - a binary
/usr/bin/time
If you want this you need to call it with its full path, you can get help about it withman time.
The /usr/bin/time binary comes with a nice -f, --format option which lets you choose the information in its output. The mentioned manpage has the full list of specifiers under FORMATTING THE OUTPUT, here are just some suggestions that may be relevant for you:
K Average total (data+stack+text) memory use of the process, in Kilobytes.
S Total number of CPU-seconds used by the system on behalf of the process (in kernel mode), in seconds.
U Total number of CPU-seconds that the process used directly (in user mode), in seconds.
If S and U is what’s important in your case and you want those two on separate lines, your command line could look like this:
/usr/bin/time -f "%Sn%U" /path/to/program
As S and U are available for bash’s time as well, this translates to:
TIMEFORMAT=$'%Sn%U' && time /path/to/program
It’s worth noting that the bash keyword is able to output milliseconds while the binary does only output centiseconds. The keyword may also be faster, as no external program needs to be called.
For an overview on the timing topic, I recommend reading man 7 time.
By default, there are two time commands on your system:
- a
bashshell keyword
This is called when you runtime, you can get help about it withhelp time. If you want to tweak its output, read about theTIMEFORMATvariable inman bash. - a binary
/usr/bin/time
If you want this you need to call it with its full path, you can get help about it withman time.
The /usr/bin/time binary comes with a nice -f, --format option which lets you choose the information in its output. The mentioned manpage has the full list of specifiers under FORMATTING THE OUTPUT, here are just some suggestions that may be relevant for you:
K Average total (data+stack+text) memory use of the process, in Kilobytes.
S Total number of CPU-seconds used by the system on behalf of the process (in kernel mode), in seconds.
U Total number of CPU-seconds that the process used directly (in user mode), in seconds.
If S and U is what’s important in your case and you want those two on separate lines, your command line could look like this:
/usr/bin/time -f "%Sn%U" /path/to/program
As S and U are available for bash’s time as well, this translates to:
TIMEFORMAT=$'%Sn%U' && time /path/to/program
It’s worth noting that the bash keyword is able to output milliseconds while the binary does only output centiseconds. The keyword may also be faster, as no external program needs to be called.
For an overview on the timing topic, I recommend reading man 7 time.
edited 8 hours ago
answered 9 hours ago
dessert
20.9k55896
20.9k55896
add a comment |
add a comment |
Gorid is a new contributor. Be nice, and check out our Code of Conduct.
Gorid is a new contributor. Be nice, and check out our Code of Conduct.
Gorid is a new contributor. Be nice, and check out our Code of Conduct.
Gorid is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1092983%2fproperly-measure-execution-time-for-benchmarking%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
time sleep 10– j-money
21 hours ago