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:
- Re: [Day 235] Opengl’s pixel format takes a long time (NVidia)
- OpenGL Context creation time on Win32 (NVidia)
- Slow window creation with SDL_WINDOW_OPENGL flag (NVidia)
- ThreadAffinity being changed by OpenGL / ChoosePixelFormat (AMD)
- OpenGL Initialization is very slow (AMD)
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.