When programming a small OpenGL application using Windows Forms, I discovered something using a profiler that I thought was pretty wonky.
I'm using a System::Windows::Forms::Timer to detect a combination of mouse idling and some other user input. The tick functionality is useful, but on occasion I want to 'reset' the timer. You can't really do this directly, but you get the correct effect by doing this:
this->someTimer->Stop();
this->someTimer->Start();
The timer interval is 50ms. Sometimes my 'reset' code here is run every 30ms. To my surprise, this is a very taxing thing to do - 30% of my program execution is often in these two lines! And it isn't a case of calling these two lines too often. In certain contrived situations this code is called as often as OpenGLSwapBuffers()
for example, but no more. I interpret this as meaning that these two lines cost roughly half as much my entire render loop!
Currently I'm using a workaround, but the timer method is a little more elegant. I'm very curious - why are these two lines so computationally expensive? What am I missing? Is there a better way to reset a timer?