Ostrich888's blog

By Ostrich888, history, 4 years ago, In English

Hello Everyone!

I am currently using Windows 10. I run my C++ code in Sublime Text 3 which take around more than 2 sec to run a code which is too slow (I am just printing a variable). I have also tried to include precomplied header for stdc++.h but still running time is same. Can somebody please help me with this issue ?

Thank You

  • Vote: I like it
  • +15
  • Vote: I do not like it

| Write comment?
»
4 years ago, # |
  Vote: I like it +5 Vote: I do not like it

Don't include the stdc++.h header file, rather include the required header files manually to decrease the compile time.

  • »
    »
    4 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    It decreases the time by 1sec when I am only including iostream but as I have already precompiled stdc++.h it should not take much time.

»
4 years ago, # |
  Vote: I like it +8 Vote: I do not like it

I think you did something wrong on precompiling. In my case, precompiling reduced the compile time of bits/stdc++.h to about 0.7s.

  1. Are you using #include "bits/stdc++.h" instead of #include <bits/stdc++.h>? Only the first one work with precompilation.
  2. Is your precompiled stdc++.pch file located on (your_source_code_location/bits/~)?

Check these two. It will just use original non-precompiled stdc++.h file if one of those two fails.

  • »
    »
    4 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I am using the first point correctly .

    Regarding second point I do not understand the location of path much but the path of my precompiled file is

    C:\Program Files\mingw-w64\mingw64\lib\gcc\x86_64-w64-mingw32\8.1.0\include\c++\x86_64-w64-mingw32\bits\stdc++.h.gch .

    Is it correct?

    • »
      »
      »
      4 years ago, # ^ |
      Rev. 3   Vote: I like it +1 Vote: I do not like it

      I don't know much about technical stuff so I can't judge whether that'll work or not. I can only say whether yours differ from mine.

      In my case, I made a bits file within the SAME folder as my source.cpp file. my stdc++.pch is located within that new bits file I've created.

      setup

      Here a.cpp is my source code file, bits and ext contains my precompiled header files stdc++.pch and pb_ds stuffs respectively.

      • »
        »
        »
        »
        4 years ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        I tried putting my source cpp file in the folder that is in the picture but it is still showing 2 sec. I think there should be a way to tell sublime explicitly that precompiled files are in a particular path.

        • »
          »
          »
          »
          »
          4 years ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          Btw the compilation command matters too. The commands you used to precompile your header must match the command you're using to run your executable.

          Version matters too. If you precompile your header with C++14, it won't work when you run your executable with C++17.

          • »
            »
            »
            »
            »
            »
            4 years ago, # ^ |
              Vote: I like it 0 Vote: I do not like it

            In the build system I am using C++ Single File. How can I get the information about what are the flags and version this build system is using?

            • »
              »
              »
              »
              »
              »
              »
              4 years ago, # ^ |
                Vote: I like it 0 Vote: I do not like it

              Not entirely sure (I use a custom build system). I think you should be able to find it on google tho.

              • »
                »
                »
                »
                »
                »
                »
                »
                4 years ago, # ^ |
                  Vote: I like it 0 Vote: I do not like it

                Thank you so much for your help. It really helped a lot.

    • »
      »
      »
      4 years ago, # ^ |
      Rev. 2   Vote: I like it 0 Vote: I do not like it

      hey did you get it? Ostrich888

  • »
    »
    4 years ago, # ^ |
    Rev. 2   Vote: I like it 0 Vote: I do not like it

    What is difference between "bits/stdc++.h" and <bits/stdc++.h>?

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Make sure that you compiled stdc++.h with your compilation flags. For example, my flags are

-std=c++17 -O2 -Wall -Wextra -DLOCAL

so I would compile stdc++.h with those flags.

»
4 years ago, # |
  Vote: I like it -12 Vote: I do not like it

east or west, codeblocks is best :D