C.1. Measure PerformanceBefore you optimize your code, you need a way to measure performance objectively so that you'll know when you've made an improvement. GLUT provides glutGet( GLUT_ELAPSED_TIME ), which applications can use to obtain platform-independent timing information. It returns an integer count of milliseconds elapsed since the application started. Many platforms, however, provide platform-specific routines for obtaining time information, which might provide more precision. If you choose to use GLUT_ELAPSED_TIME, you'll need to measure several frames to obtain an accurate measurement on such a coarse timer. Because OpenGL supports a client-server model, OpenGL often buffers commands internally. As a result, some OpenGL commands return to the application before they execute. This behavior can skew performance measurements if you attempt to time such a command. You can block until OpenGL executes all commands by using glFinish(), however. Because glFinish() has a nonzero cost, you'll want to measure several rendered framespossibly hundredsand then use a single glFinish() call before obtaining time information. This amortizes the expense of the glFinish() call over all rendered frames, increasing the accuracy of the timing measurement.
flylib.com © 2008-2017. If you may any questions please contact us: flylib@qtcs.net |