This is my code:
#include <iostream>
using namespace std;
int main()
{
cout << "Hello, World!";
return 0;
}
Picture of my screen. Isn’t c++ supposed to be extremely fast? Why is my code taking this long to run? I’m running on Visual Studio Code, Windows 10, 6GB RAM.
>Solution :
To be more specific: What you’re doing actually has three steps:
You move to a specific directory (via the cd command). Then we have code compilation (calling g++). Lastly we have running the actual executable (named test in your picture).
It’s likely that running just the executable would yield a lower time than all three steps you have in the screenshot.
If the executable is still slow, consider trying an optimization flag for g++ as found here: https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html. These flags can make compilation slower, but the actual execution faster.
For fun I timed your example code on WSL using the time command:
csm10495@csm10495-desk:/mnt/c/Users/csm10495/Desktop $ time g++ test.cpp -o test
real 0m0.235s
user 0m0.117s
sys 0m0.043s
csm10495@csm10495-desk:/mnt/c/Users/csm10495/Desktop $ time ./test
Hello, World!
real 0m0.005s
user 0m0.002s
sys 0m0.000s
So for me the executable runs in .005s, while the compile took .235s.