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.
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.