# OpenGL Strange timing behavior

This topic is 2206 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I am profiling a routine (ProcessTexture) that uses OpenGL to do some image procesing. To get a good idea on the routinies performance, I take the average of several trials:

 GLuint64 total = 0; for (int i = 0; i < 1000; ++i) { glBeginQuery(GL_TIME_ELAPSED, query); ProcessTexture(input_texture, output_texture); glEndQuery(GL_TIME_ELAPSED); GLuint64 t = 0; glGetQueryObjectui64v(query, GL_QUERY_RESULT, &t); printf("Trial %d = %f\n", i, double(t)*1.0e-6); total += t; // Sleep(2000); } double average_millisec = double(total)/1000*1.e-6; printf("average = %f\n", average_millisec); 

Now, the above works well... except if I uncomment the Sleep() or replace Sleep() with an expensive CPU algorithm. In this case, instead of all trials having similiar timing numbers, what happens is about 10 seconds into it, the timings approximately double. Then after another 5 to 8 seconds the timings double again! (not exactly double, but close). My question is why? Why would anything outside of the glBeginQuery() and glEndQuery() affect the timings? In my example, the timings without the Sleep() is 1.3ms, but with Sleep() the ProcessTexture() takes over 7.0ms. GPU: Nvidia GTX 580, windows 7 64. Edited by execute42

##### Share on other sites
Here are my actual tiiming numbers:
Without the Sleep(), I ran 20,000 trials...

trial 1 = 1.50883
trial 2 = 1.28858
trial 3 = 1.32256
trial 4 = 1.29549
.... skip a few .....
trial 19996 = 1.2768
trial 19997 = 1.28842
trial 19998 = 1.2767
trial 19999 = 1.27475
Average preprocessing time (ms): 1.28239

And with the Sleep():
trial 1 = 1.65331
trial 2 = 1.40234
trial 3 = 1.40093
trial 4 = 1.39814
trial 5 = 1.41034
trial 6 = 2.59654
trial 7 = 2.59462
trial 8 = 2.59773
trial 9 = 2.60067
trial 10 = 7.92922
trial 11 = 7.88902
trial 12 = 7.56467
trial 13 = 7.57318
trial 14 = 7.5655
trial 15 = 7.492
trial 16 = 7.4943
trial 17 = 7.50099
trial 18 = 7.49405
trial 19 = 7.50326
Average preprocessing time (ms): 4.92952

Is one explanation for this behavior that since that due to somewhat of an incorrect usage of the OpenGLdriver or operating system are adding a bunch of latency?

##### Share on other sites
No, the reason is changing performance states. Having low GPU load reduces performance state.

1. 1
2. 2
3. 3
Rutin
22
4. 4
JoeJ
16
5. 5

• 14
• 29
• 13
• 11
• 11
• ### Forum Statistics

• Total Topics
631775
• Total Posts
3002284
×