SetPixelFormat() delay

I was curious about your post, so I did some timing here with a recent NVidia GPU and drivers.

After several consecutive runs, here’s what I see:

 520.0 msec = ChoosePixelFormat
   0.1 msec = SetPixelFormat
   0.1 msec = wglGetPixelFormatAttribivARB (Query num formats)
  16.2 msec = wglGetPixelFormatAttribivARB (Query each of all 670 formats) 
  13.8 msec = wglChoosePixelFormatARB

Websearching around, this is a well-known issue.

Apparently, in the first call to a *PixelFormat API, the display system and/or graphics driver does quite a bit of loading and setup.

A few links on this. See the first one in particular:

Based on this, my suspicion is that when running your app under an instrumented debugger, the debugger may have already “taken the hit” of initializing the connection to the graphics driver for you, so that what you perceive as your app’s init is fast. But that’s a guess.