Reputation: 33
I started using Vim for C++ competitive programming and i have a problem . For compiling i am using MinGW g++ compiler as in tutorials . Code compiles , but i have issue that , any program compiles and runs extremly slow . For example to compile and run next code:
#include <iostream>
using namespace std ;
int main()
{
cout<<"Hello World"<<endl;
}
(simplest programm ever) It takes 6 to 8 seconds to compile and run .
In Vim itself i have this shortcut :
autocmd filetype cpp nnoremap <C-r> :w <bar> !g++ -std=c++14 -Wall % -o %:r && %:r.exe <cr>
Can you help me to findout why i am having such an issue . For instance William Lin ( competetive programmer also uses Vim and mine shortuc is similar to his , but his programs runs instantly ).
Upvotes: 1
Views: 815
Reputation: 1
Basically william and most of other CPers use what's called precompiled header file, to fasten up the compilation time, not the execution. To do that first go to your bits folder. I installed using msys2 so here's my path:
C:\msys64\mingw64\include\c++\12.1.0\x86_64-w64-mingw32\bits
when you go inside this folder, you will se one file named stdc++.h
. That is the file which gets compiled everytime you inculde bits/stdc++.h
in the source code.
Compilation time is increased because it also inculdes some unnecessary headers which are generally not used. But for the sake of readability and short code, programmers generally include this file.
Now to precompile this file open your terminal in the same folder as bits or in windows you can click address bar and type cmd and press enter to open up the command prompt in the same folder.
After that run the following command g++ stdc++.h -std=c++17
. Though you can change c++17 part to whatever you like (14 or 20) I recommend using c++17 because it is supported by most of the new online judges and is generally used. You will see one stdc++.gch
file created in you folder which will be of a large size(~93 MB for c++17 and ~103 MB for c++20).
Now whenever you will compile your file. It would not take much longer.
Upvotes: 0
Reputation: 33
It's an shame to say this , but problem was in Antivirus . As i think it slow downs process to check for some virus
Upvotes: 1