Working with clock_t in C -


this question has answer here:

i'm working on little school project re-code spaceinvaders game, without using ncurses, basic libraries, , want use time print screen-buffer every time, need know when print user won't feel screen lagging.

i started using clock_t structure test :

clock_t stime = clock(); sleep(3); clock_t etime = clock(); unsigned long millis = ((etime - stime) * 1000) / clocks_per_sec; printf("%lu\n",millis); 

but output 0 time, want know why , how can fix can see milliseconds, or nanoseconds

add print statements code:

clock_t stime = clock(); sleep(3); clock_t etime = clock(); // print etime , stime , (etime - stime) * 1000 , clocks_per_sec unsigned long millis = ((etime - stime) * 1000) / clocks_per_sec; printf("%lu\n",millis); 

you see numerator smaller denominator in expression, therefore since using integer math truncate result , zero


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -