c++ QueryPerformanceCounter performance spikes -
i created simple program determinate how long queryperformancecounter
call takes. takes around 8 nanoseconds on computer time time can see spikes 500 usecs per call.
some details:
visual studio 2013, c++
large_integer ll; queryperformancefrequency(&ll); int steps = 10000000; large_integer t1, t2; long long dt=0, dtavg=0, dtmax=0; double nanosecmult = 1000000000.0 / ll.quadpart; double usecsecmult = 1000000.0 / ll.quadpart; (int = 0; < steps; i++) { queryperformancecounter(&t1); queryperformancecounter(&t2); dt = t2.quadpart - t1.quadpart; dtavg += dt; if (dt>dtmax) dtmax = dt; } double dtd = dtavg*usecsecmult / steps; double dtdmax = dtmax * usecsecmult; printf_s("steps: %d, dtavg: %.12f usec, dtmax: %.6f usec\n", steps, dtd, dtdmax);
output example:
... steps: 10000000, dtavg: 0.008456895938 usec, dtmax: 3.893501 usec steps: 10000000, dtavg: 0.008427907056 usec, dtmax: 222.991405 usec steps: 10000000, dtavg: 0.008488256317 usec, dtmax: 452.353993 usec steps: 10000000, dtavg: 0.008457002125 usec, dtmax: 433.594398 usec steps: 10000000, dtavg: 0.008493247077 usec, dtmax: 9.910729 usec steps: 10000000, dtavg: 0.008432154511 usec, dtmax: 10.618638 usec steps: 10000000, dtavg: 0.008588921008 usec, dtmax: 480.670362 usec ...
so dtavg
same time difference in last digits dtmax
jumps lot 2 usecs 550 usecs
questions:
- does have ideas why can happen , if can eliminate these spikes?
- does take these 500 usecs call (with blocking thread time) or returns "incorrect" values doesn't effect thread execution?
thank you.
at guess, what's happening once in while you're timing process switch--that is, process running , returning successive values clock--but @ point, process scheduler decides other process should little cpu time (or @ least scheduler runs figure out whether other process should cpu time, anyway).
when happens, 1 of calls qpc going show larger delta of rest.
Comments
Post a Comment