0

After compiling my code in C, I use “time ./main” from the terminal (Mac OS X) and get

real    0m0.004s
user    0m0.001s
sys     0m0.002s

But using <time.h> as described here, I get an elapsed time of 0.000217 seconds. So I’m just wondering how these two measurements differ.

Community
  • 1
  • 1
user1799323
  • 649
  • 8
  • 25
  • 1
    On current hardware and operating system such a small time is not significant. You practically need to change your program (or its invocation) to have a time of a few seconds (or at least half of a second), and you need to repeat the benchmark several times. – Basile Starynkevitch Nov 20 '13 at 08:54

1 Answers1

2

time ./exe will measure more things - loading the exe, starting the program, finishing the program, etc. These are a lot of things, especially of there are loading of dynamic libraries and things like this.

Using time.h you can measure the time from line x to line y - this will not include anything else (like startup time, etc.)

Also note @BasileStarynkevitch 's comment under the question.

Kiril Kirov
  • 37,467
  • 22
  • 115
  • 187