When submitting a solution in C++, please select either C++14 (GCC 6-32) or C++17 (GCC 7-32) as your compiler. ×

pranshukas's blog

By pranshukas, history, 3 years ago, In English

I am using Sublime Text Editor for Writing C++ Programs but it's taking too much time to Compile even small Programs. Even printing Hello World takes 4-5s.

I have been using Windows 10, My PC Configuration is — i7 9750H, 16GB Ram, and 512GB SSD. I am still wondering why is it still slow. I have seen many Competitive Programmers during screencasting videos using Sublime text and their Compile Time is merely 0.8-1.2s. But mine is taking too much time which cost me patience and time During Contests.

One thing that I have seen is those Competitive Programmers were using macOS or Linux. I was wondering if Sublime Text really slow on Windows or I have done some mistakes while installing it.

I have tried Googling my Problem but unable to find any solution, I had asked this Question on Stackoverflow also but there also I didn't get any reply.

Please Someone Help me fixing it or comment on some related article that I can read to fix it.

Below is ScreenShot even this small Program took 15.3s ->

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

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

I suggest using precompiled header.

  • »
    »
    3 years ago, # ^ |
      Vote: I like it -11 Vote: I do not like it

    I tried making my Precompiled Header Files and it's running fine on my local system but when I am trying to submit it on online judges it's showing no such files found.

    How can I make a precompiled file that would be automatically attached while submitting solutions on Online Judge.

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

      Refer to point 5 on this blog. I have done using this.

      • »
        »
        »
        »
        6 months ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        When I copy paste the path in cmd Its showing this error: 'C:\MinGW\lib\gcc\mingw32\6.3.0\include\c++\mingw32\bits' is not recognized as an internal or external command, operable program or batch file.

        What shall I do now

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

          You need to find the location of your bits/stdc++.h.

          Create a c++ file which includes that header and open that folder on command line.

          Then run the following command

          g++ -H file_name.cpp
          

          then it will show the location of the header on the first line

        • »
          »
          »
          »
          »
          6 months ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          Environment variable

»
3 years ago, # |
  Vote: I like it +25 Vote: I do not like it

Try disabling your anti-virus if you have any 3rd party anti-virus.

When my compilation slowed down disabling anti-virus helped.

»
3 years ago, # |
  Vote: I like it +11 Vote: I do not like it

I have used sublime text both on windows and ubuntu , and it does seem that sublime works faster on linux systems. Still, it is weird. More than 15 seconds to run the program , it is just crazy. On ubuntu, it takes about 0.5 to 1.5 seconds in general, if I have precompiled headers. For windows, it takes about 3-5 seconds, even with precompiled headers. Still, I have seen people run sublime quite smoothly on windows, so yeah it is weird.Sublime behaves differently on different systems, and on different machines too, which sucks bad.

  • »
    »
    3 years ago, # ^ |
      Vote: I like it -8 Vote: I do not like it

    The Same Thing happens to me. But generally, the compilation is more than 5-10s. Have You Created Your own build System or Sublime Text c++11 one?

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

      I am using the sublime text c++ 11 one. I think that the custom build is slightly slower, but again, some other people might have seen different results.

»
3 years ago, # |
  Vote: I like it -28 Vote: I do not like it

Try "bits/stdc++.h" instead of <bits/stdc++.h>

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

Earlier I used to get speed of 0.8 -1.5 sec. Now after reinstalling all it takes first compilation to 15-20 secs..After that it return to normal speed of 1-2sec..I also used precompiler headers but no effect

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

As someone already mentioned, it is a common issue with third-party antivirus. Try excluding those folders from antivirus where your .exe files get created.
Immediate solution would be to switch to an online IDE.

ps: If you have McAfee antivirus, there is no solution but either uninstall it or deactivate there Realtime scanning whenever you compile your code because they don't provide folder exclusion option.

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

    Yeah, I have McAfee Antivirus installed, will uninstalling it and switching to Windows defender will solve the Problem? Or will I need to turn of Windows Defender too?

    One more thing Can just turning off Real-Time Scanning in McAfee will solve the issue ?

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

      Try to do compilation after uninstalling McAfee and if it works out, then uninstall it forever. My personal opinion, McAfee is shit and it slows down your system more than it protects it. If you are a casual user (not much into the deep web and torrents), then Windows defender will get the job done. Just never install untrusted applications and you should be good to go

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

Just write around 8-10 most frequently used header files instead of writing <bits/stdc++.h>. This greatly decreased my compile time.

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

In my laptop, there is a pre-installed app that could switch my laptop between performance/battery mode (not the one from Windows Settings/Control Panel). Compiling a hello world program (with bits/stdc++.h precompiled) takes 0.3-0.5s on performance mode and 1.2-1.4s on battery mode. Turning off Windows Defender reduces the compilation time by ~0.1s in my case.

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

    Can you tell me the name of the app, please? Is it the one which comes with HP laptops?

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

Install WSL, and make your build system run commands on WSL terminal, rather than CMD.

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

    Does this shorten compilation time?

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

Earlier I had the same issue. It took around 15-17 seconds. After disabling my antivirus it came down to 1.5-2 second.Use precompiled headers or stop using <bits/stdc++.h>

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

    I am not able to understand what does it mean by Precompiled Header File. I made a header file temp.h and included in my program #include "temp.h" but when I submitted it on online judge it's giving Compilation Error. No Such files found. But it's running on my local system.

    Can You Please Help me out. How to create Precompiled Header Files which would work on online judges as well. Please tell me or attach any tutorial or video so that I can learn.

    I tried Googling up end up getting confused. Even I am asking people here in the community but I don't know why people are insanely just downvoting me instead of helping.

    Hope You Help !! Thanks

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

Also, turn off O2 optimization will also reduce compilation time if you're not stress testing.

»
9 months ago, # |
  Vote: I like it 0 Vote: I do not like it

thankuuuu so much... i was too much frustrated bcoz of this f***ing mcafee