PDA

View Full Version : Timing in Linux



DBQ
August 7th, 2007, 09:36 PM
Hey Guys,
I was wondering what is more accurate way of timing the program, using the times function in #include <sys/times.h> or to use the command line time utility. I was advised before not to use the command line utility. Any ideas would be good.

PandaGoat
August 7th, 2007, 10:51 PM
You should use the system header. Using the system() to call something on the command line is taking the long route to using the system header; the commands for the terminal just use the system header.

hod139
August 8th, 2007, 01:16 AM
Here is a good article about accurate timing of functions:
http://www.cs.rpi.edu/~musser/gp/timing.html

nitro_n2o
August 8th, 2007, 03:07 AM
you can also the time utility for something quick

time ./myprogram
if the program output stuff on the screen, for debugging for example you can get rid of it to /dev/null

time ./myporgram > /dev/null
I'm not sure how accurate is this... but it's great as a quick solution

fatsheep
August 8th, 2007, 04:37 AM
you can also the time utility for something quick

time ./myprogram
if the program output stuff on the screen, for debugging for example you can get rid of it to /dev/null

time ./myporgram > /dev/null
I'm sure how accurate is this... but it's great as a quick solution


Hey Guys,
I was wondering what is more accurate way of timing the program, using the times function in #include <sys/times.h> or to use the command line time utility. I was advised before not to use the command line utility. Any ideas would be good.

:KS

slavik
August 9th, 2007, 06:58 AM
the thing with time is that it knows where your code takes time ... it reports 3 metrics, real, user, system.

real = total time to run the program
user = how much time the program is in userspace (not accessing system stuff)
system = how much time syste spends on giving services to the program (writing file, connecting to network, etc.)

this allows you to somewhat gauge your program's performance and allow you to optimise they way you do things. :) (valgrind is supposed to be able to tell you which function in your code takes time and such)