A family of Microsoft suites of integrated development tools for building applications for Windows, the web, mobile devices and many other platforms. Miscellaneous topics that do not fit into specific categories.
Hello Pranay,
Your 0.21 s measurement covers only compilation. “Run Code” does more than that: Code Runner compiles the file, then starts the generated .exe, either in the Output panel or in the integrated terminal. The best approach is to time each of these stages separately.
Step 1: Time the executable by itself
In PowerShell, in the folder with your program, compile once and then run the .exe several times:
powershell
gcc hello.c -o hello.exe
Measure-Command { .\hello.exe } | Select-Object TotalMilliseconds # 1st run right after compiling
Measure-Command { .\hello.exe } | Select-Object TotalMilliseconds # 2nd run
Measure-Command { .\hello.exe } | Select-Object TotalMilliseconds # 3rd run
- Only the first run after compiling is slow: the delay is probably antivirus scanning of the freshly created
.exe(Microsoft Defender real-time protection checks new executables before they run). See Step 4. - All runs are fast: the program and GCC are fine. The delay comes from Code Runner or the terminal, so go to Step 2.
- All runs are slow: something in the system is affecting every process start. Test a plain
cmd /c exitthe same way for comparison.
Step 2: Compare Code Runner’s two run modes
Code Runner has a setting called code-runner.runInTerminal. Try both values in settings.json:
json
"code-runner.runInTerminal": false,
"code-runner.showExecutionMessage": true
-
false(Output panel): no terminal is involved. WithshowExecutionMessageon, the Output panel shows[Running]and[Done]messages with the elapsed time. -
true(integrated terminal): if this mode is noticeably slower, especially on the first run, the cost is the terminal and shell starting up, not your program.
Step 3: If the terminal is the bottleneck, check your shell startup
In a regular PowerShell window, compare startup with and without your profile:
powershell
Measure-Command { powershell -Command exit } | Select-Object TotalMilliseconds
Measure-Command { powershell -NoProfile -Command exit } | Select-Object TotalMilliseconds
A large difference means a slow PowerShell profile, such as modules or prompt themes loading at startup. You can fix the profile, or set the VS Code default terminal profile to Command Prompt and compare again.
Step 4: If antivirus scanning is the cause
Don’t turn Microsoft Defender off. Windows 11 supports a Dev Drive: if you keep your projects there, Defender scans them in performance mode, which is asynchronous. Microsoft documents this as a safer alternative to folder exclusions.
If the cause is still unclear, please reply with:
- How long the delay is, in seconds.
- Your
code-runner.runInTerminalvalue. - The three timings from Step 1.
With those numbers, the cause can be pinned down exactly.
Hope this helps. If it does, please consider accepting the answer.
Fontes:
- Code Runner – repositório oficial (configurações)
- Set up a Dev Drive on Windows 11 – Microsoft Learn
- Protect Dev Drive using performance mode – Microsoft LearnHello Pranay, Your 0.21 s measurement covers only compilation. “Run Code” does more than that: Code Runner compiles the file, then starts the generated
.exe, either in the Output panel or in the integrated terminal. The best approach is to time each of these stages separately. Step 1: Time the executable by itself In PowerShell, in the folder with your program, compile once and then run the.exeseveral times: powershellgcc hello.c -o- Only the first run after compiling is slow: the delay is probably antivirus scanning of the freshly created
.exe(Microsoft Defender real-time protection checks new executables before they run). See Step 4. - All runs are fast: the program and GCC are fine. The delay comes from Code Runner or the terminal, so go to Step 2.
- All runs are slow: something in the system is affecting every process start. Test a plain
cmd /c exitthe same way for comparison.
code-runner.runInTerminal. Try both values insettings.json: json"code-runner.runInTerminal"-
false(Output panel): no terminal is involved. WithshowExecutionMessageon, the Output panel shows[Running]and[Done]messages with the elapsed time. -
true(integrated terminal): if this mode is noticeably slower, especially on the first run, the cost is the terminal and shell starting up, not your program.
A large difference means a slow PowerShell profile, such as modules or prompt themes loading at startup. You can fix the profile, or set the VS Code default terminal profile to Command Prompt and compare again. Step 4: If antivirus scanning is the cause Don’t turn Microsoft Defender off. Windows 11 supports a Dev Drive: if you keep your projects there, Defender scans them in performance mode, which is asynchronous. Microsoft documents this as a safer alternative to folder exclusions. If the cause is still unclear, please reply with:Measure-Command- How long the delay is, in seconds.
- Your
code-runner.runInTerminalvalue. - The three timings from Step 1.
- Only the first run after compiling is slow: the delay is probably antivirus scanning of the freshly created