Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compute run time for a C program in ubuntu

Tags:

c

gcc

I tried >>time ./a.out

got

real 0m0.035s

user 0m0.008s

sys  0m0.004s

what it really means?

when I repeated I got

real 0m0.012s

user 0m0.000s

sys  0m0.012s

if I try this many times each time I am getting different output why? how can I solve it.

like image 971
Sarath Babu Avatar asked Jan 28 '26 06:01

Sarath Babu


2 Answers

Each of those are the different runtimes of your program.

  • Real is the actual wallclock time it took to run

  • sys is the amount of time the system spent while executing your program (i.e. time spent by the kernel)

  • user is the amount of time that was spent in user-mode executing it (i.e. time spent excuting where you weren't in the kernel).

like image 107
Kurtis Nusbaum Avatar answered Jan 30 '26 20:01

Kurtis Nusbaum


There is no "solution" because there is no problem. You are running a multi tasking system and it depends on the load how fast you get the response. What you can do is running it a few times and take the average as "guide".

like image 31
Friedrich Avatar answered Jan 30 '26 19:01

Friedrich



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!