最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c++ - how to profile compile time - Stack Overflow

programmeradmin4浏览0评论

Over time my project compile time has increased. But I don't know where the longest compile time is.

It's just a small application with only 2 translation units. One compiles to an exe and takes care of the platform and rendering with opengl. The other compiles to a dll and handles most of my application business like drawing the ui and processing data. The exe will then load the dll portion at runtime.

They share a lot of code and use the same compiler flags and libraries. The exe portion has only 1000 lines of code while the dll portion has 3000 lines of code (no including shared cpp)

The exe portion takes 1 second to compile but the dll portion only takes 0.4 seconds (using vcperf)

If I remove those lines and keep the headers and shared cpp files. The exe part does get reduced to 0.4 seconds, the dll has barely any noticeable effect

also the code is written in procedural c style, so no crazy stuff like templates, objects or inheritance here The only difference I can see in the two translation units is that 80% of the exe code is opengl calls, while the dll part has none

i have no idea how compiler work and why the compile time is so different. i would love to know is anyone encounter this and how they handle with these

edit: code sample from exe part

glActiveTexture(GL_TEXTURE0 + ImageSlot);
        glBindTexture(GL_TEXTURE_2D, AppData->WhiteTestTexture.id);
        glUniform1i(ShaderInput->UniformLocation[SUL_Texture0], ImageSlot);
        
        ImageSlot++;

        GL_DEBUG_ASSERT;

        rlUpdateVertexBuffer(AppData->RectVertexBufferBlock, AppData->RectVertexData, VertexCount * sizeof(Vector4), 0);
        rlUpdateVertexBuffer(ShaderInput->VertexBufferHandle[VB_ColorBuffer], AppData->RectColorData, VertexCount * sizeof(Vector4), 0);
        rlUpdateVertexBuffer(ShaderInput->VertexBufferHandle[VB_TexCoordBuffer], AppData->RectTexCoordData, VertexCount * sizeof(Vector2), 0);
        
        rlUpdateVertexBufferElements(AppData->RectIndexBuffer, AppData->RectIndexData, AppData->RectIndexDataCount * sizeof(unsigned int), 0);

        glDrawElements(GL_TRIANGLES, AppData->RectIndexDataCount, GL_UNSIGNED_INT, 0);
        rlDisableVertexArray();
        rlDisableVertexBuffer();
        rlDisableVertexBufferElement();

some rl calls were just a wrapper or a direct gl calls

build command: exe:

cl -w -Zi /source-charset:utf-8 /MD /Gm- ..\code\d_main.cpp raylib.lib /link user32.lib opengl32.lib winmm.lib gdi32.lib shell32.lib ole32.lib comdlg32.lib /libpath:..\lib /out:DAPP.exe 

dll:

cl /source-charset:utf-8 -w -Zi /Gm- /MD ..\code\d_interface.cpp raylib.lib -LD /link /PDB:DSourceInterface_%timestamp%.pdb /dll user32.lib opengl32.lib winmm.lib gdi32.lib shell32.lib ole32.lib comdlg32.lib /libpath:..\lib /out:DSourceInterface.dll /export:Interface_IBabyDispose /export:Interface_IBabyInit /export:Interface_IBabyLoop
发布评论

评论列表(0)

  1. 暂无评论