c - when I run the program for the second time it doesn't give me correct execution time -


i have c code, when try calculate time of small pieces of processing code first execution. gives me 30 ms, when turn of exe file , run again gives me 1 ms, , time time calculation , each time run program calculation values different previous one, if turn off pc , turn it, gives me 30 ms first execution , 1 ms other executions how can same time , free used memory , run program overwrite memory problem not solved until reboot pc help

start_time=clock(); encryption(); end_time=clock(); cpu_time_used_totlal_enc +=(double) (end_time-start_time) / clocks_per_sec; 

this problem called "warmup": when want performance test code, need run code several times (say, 10 times). run 100'000 times , measure how long takes , divide 100'000 average. single measurement of runtime useless, unless runtime @ least 1 minute.

the reason warmup problems modern oss , languages kind of tricks make code execute faster. example, call encryption() might invoke function in shared library.

those libraries loaded lazily, i.e. it's loaded first time when code calls function. when loaded, os keeps in cache since chances need again.

that's why first few runs of application have different runtime next 10'000 runs.


Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -