Author Topic: Why do all my .cpp files take 5 seconds or longer to compile  (Read 4752 times)

Offline speedreadersteve

  • Multiple posting newcomer
  • *
  • Posts: 17
Why do all my .cpp files take 5 seconds or longer to compile
« on: February 01, 2023, 05:43:38 am »
They used to take only 1 second or shorter, but ever since I compiled a 500+ line file - mostly of comments and ~200 lines code, a lot of statements in main() - it's taken a consistent 6 seconds.  This adds up when I'm debugging with print tests.

I'm using v20.03
« Last Edit: February 01, 2023, 06:00:38 am by speedreadersteve »

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7668
    • My Best Post
Re: Why do all my .cpp files take 5 seconds or longer to compile
« Reply #1 on: February 01, 2023, 05:50:42 am »
They used to take only 1 second or shorter, but ever since I compiled a 500 long file - mostly of comments and ~200 lines code, a lot of statements in main() - it's taken a consistent 6 seconds.  This adds up when I'm debugging with print tests.

Single source file project or more than one "C" or "C++" file?
If more than one, using an pre-compilied header might help.

If only one file, I would look to anti-virus or try defragging the harddrive (Note, that is if you are still using an normal hardrive; I am not sure if Solid State Harddrive is a good idea to defrag)

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline speedreadersteve

  • Multiple posting newcomer
  • *
  • Posts: 17
Re: Why do all my .cpp files take 5 seconds or longer to compile
« Reply #2 on: February 01, 2023, 05:58:35 am »
I look at workspace and it contains nothing.  Every file is by itself. 

I'm new to programming, so I'm not too familiar with setting up projects or what they look like.  I always just start a new file rather than a new project, since I was more interested in learning the language than the platform.  The platform of codeblocks just looked simple enough for my needs.

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353

Offline speedreadersteve

  • Multiple posting newcomer
  • *
  • Posts: 17
Re: Why do all my .cpp files take 5 seconds or longer to compile
« Reply #4 on: February 01, 2023, 09:37:47 pm »
"Anti virus scanner?
Other processor load?
a build log? (https://wiki.codeblocks.org/index.php/FAQ-Compiling_(general)#Q:_How_do_I_report_a_compilation_problem_on_the_forums.3F )"

Broken link on my end

Here's a build log

Set variable: PATH=C:\Program Files (x86)\CodeBlocks\MinGW\bin;C:\Program Files (x86)\CodeBlocks\MinGW;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\MinGW\bin;C:\Program Files\dotnet;C:\Program Files\Git\cmd;C:\Users\User\AppData\Local\Microsoft\WindowsApps;C:\Users\User\AppData\Roaming\npm;C:\Program Files (x86)\FAHClient;A:\Apps\SocketeQ\windowsandroid_root\system\bin;A:\Apps\SocketeQ\windowsandroid_root\system\lib;C:\Users\User\AppData\Local\atom\bin;C:\Users\User\.dotnet\tools'

My two cents - It seems to be rebounding through a lot of C:drive paths, though I don't know why.  Shouldn't it just check a c++ compiler directory?
« Last Edit: February 01, 2023, 09:40:29 pm by speedreadersteve »

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7668
    • My Best Post
Re: Why do all my .cpp files take 5 seconds or longer to compile
« Reply #5 on: February 02, 2023, 04:26:42 am »
https://wiki.codeblocks.org/index.php/Main_Page

Code
https://wiki.codeblocks.org/index.php/Main_Page
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: Why do all my .cpp files take 5 seconds or longer to compile
« Reply #6 on: February 02, 2023, 10:06:05 pm »
Quote
Broken link on my end
What does this mean?

i copy the relevant part here
Code
Paste full build log here. (It is found in the 'Build log' tab). Please make always a 'rebuild' (Menu: Build->Rebuild) or a 'clean' and 'build' before you copy the full build log. 

Quote
Here's a build log

Set variable: PATH=C:\Program Files (x86)\CodeBlocks\MinGW\bin;C:\Program Files (x86)\CodeBlocks\MinGW;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\MinGW\bin;C:\Program Files\dotnet;C:\Program Files\Git\cmd;C:\Users\User\AppData\Local\Microsoft\WindowsApps;C:\Users\User\AppData\Roaming\npm;C:\Program Files (x86)\FAHClient;A:\Apps\SocketeQ\windowsandroid_root\system\bin;A:\Apps\SocketeQ\windowsandroid_root\system\lib;C:\Users\User\AppData\Local\atom\bin;C:\Users\User\.dotnet\tools'
this is not the build log but your path...

also if you post the log, please use code tags (the # symbol in the forum editor)

Offline speedreadersteve

  • Multiple posting newcomer
  • *
  • Posts: 17
Re: Why do all my .cpp files take 5 seconds or longer to compile
« Reply #7 on: February 04, 2023, 04:29:38 am »
That's what I took from the "build log" tab at the bottom.  Is there another place?

#
-------------- Build file: "no target" in "no project" (compiler: unknown)---------------

Checking for existence: D:\Documents\C++ Scripts\Hacks\Garbage throwaway hacks\garbage.exe
Executing: '"C:\Program Files\CodeBlocks/cb_console_runner.exe" "D:\Documents\C++ Scripts\Hacks\Garbage throwaway hacks\garbage.exe"' (in 'D:\Documents\C++ Scripts\Hacks\Garbage throwaway hacks')
Set variable: PATH=C:\Program Files (x86)\CodeBlocks\MinGW\bin;C:\Program Files (x86)\CodeBlocks\MinGW;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\MinGW\bin;C:\Program Files\dotnet;C:\Program Files\Git\cmd;C:\Users\User\AppData\Local\Microsoft\WindowsApps;C:\Users\User\AppData\Roaming\npm;C:\Program Files (x86)\FAHClient;A:\Apps\SocketeQ\windowsandroid_root\system\bin;A:\Apps\SocketeQ\windowsandroid_root\system\lib;C:\Users\User\AppData\Local\atom\bin;C:\Users\User\.dotnet\tools
Process terminated with status -1073741510 (0 minute(s), 9 second(s))
#
« Last Edit: February 04, 2023, 04:31:45 am by speedreadersteve »

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: Why do all my .cpp files take 5 seconds or longer to compile
« Reply #8 on: February 04, 2023, 10:20:36 am »
You have to make a rebuild to see the build process. This is all described in the link above...
1) Load your project
2) Hit Build->Rebuild
3) Copy everything from the build log
4) paste it here and using the # symbol button in the forum editor toolbar, not the keyboard. Then there should appear code tags in the editor and between there paste the log

Offline eckard_klotz

  • Almost regular
  • **
  • Posts: 200
Re: Why do all my .cpp files take 5 seconds or longer to compile
« Reply #9 on: February 05, 2023, 10:27:21 am »
Hello Speedreadersteve.

Initially you wrote:
Quote
... since I compiled a 500+ line file - mostly of comments and ~200 lines code, a lot of statements in main() - it's taken a consistent 6 seconds. ...

Please keep in mind that the compiler is not only processing the code lines written by you but all code lines in the header-files you have included. And this may result in your issue by just small changes in your self written code.

Before the compiler starts the translation of the file the preprocessor will extend your own code.
  • Every include line will be replaced by the complete content of the included file. And if an included file contains include-commands by itself the preprocessor is replacing  this include commands by the corresponding file content also.
  • If you use preprocessor-defines (maybe provided by an used library) the corresponding CONSTANTS and MACROS, used in your code, will be replaced by the code used while the definition with their #define statement.
  • This is just a very rough and general description. But I hope you understand that already the use of the #include and #define directives  could increase the workload of the complier even your own code my just contain less then 10 lines.

Especially today many modern libraries for example provided by the boost-project are based on meta-programming. But you may already have a similar effect if you just use a STL (Standard Template Library) provided by a standard C++ build suite.
  • This means that the library may contain just header-files, which define templates only.  This means before actively using this libraries, they could not be build, since especially data-types are just defined by placeholders.
  • By using them you define the specific data-type for each placeholder in your own code and based on this definition the compiler is now creating the final code of the library object you want to use.
  • This is increasing the workload of your compiler and you could compare it with the preprocessor workload.

Furthermore, if you use a meta-programming based library or a STL in a header, every cpp file that is including this header directly or indirectly will be affected by a combination of both effects.

I hope that this will give you an idea how you could blow up the build effort just by adding 1 or 2 lines of code.

You may reduce your resulting problems by a pre-compilation of your header files as suggested by the other discussion participants. Thus, please follow their advises.

However, you may already limit the initial root-cause by a refactoring of your software design.
  • Limit the dependencies between your sources as far as possible. Whenever you are able to eliminate the use of an other module or class you could eliminate the corresponding including of a header.
  • Split big header files when ever possible. If you have a header that will be included by 10 other files but every including file is only using 10% of the headers content, try to split your header in 10 smaller headers with the goal that every using source is just including one new smaller header with the needed information.
  • If possible include headers in cpp files but not in other headers to reduce indirect includes.

Do you already use Doxygen? together with the tool Dot from Graphviz ? This tool is able to provide you for every of your source-file an include graph that shows you not only the direct but the indirect included files. This graphs will help you to detect the most complex include dependencies.

Best regards,
                     Eckard Klotz.

PS.: Dear forum admin. I know, actually this is not a programming discussion. But I face very often similar issues in my own projects and had to learn over the time that the reason is not the tool (Code::Blocks, build-suite, ...) but in the most cases the software design. Thus I hope sharing my experiences will help to reduce the users frustration a little bit.

Offline speedreadersteve

  • Multiple posting newcomer
  • *
  • Posts: 17
Re: Why do all my .cpp files take 5 seconds or longer to compile
« Reply #10 on: February 11, 2023, 02:51:46 am »
It runs at 1-2 seconds now, after I rebooted my computer.  Maybe it was the CPU?