VS Code Code Runner takes several seconds to run simple C programs on Windows

Pranay Prakash 0 Reputation points
2026-10-15T19:18:14.9466667+00:00

I am facing a delay when running simple C programs in Visual Studio Code on Windows.

My setup:

  • Operating System: Windows 11
  • Editor: Visual Studio Code
  • Language: C
  • Compiler: GCC (MinGW)
  • Laptop: MSI Katana 15, Intel Core i7 13th Gen, 16 GB RAM
  • I use the Code Runner extension to run my C programs.

Problem:

When I click the "Run Code" button in VS Code, there is a noticeable delay before my program starts producing output. This happens even with simple programs, such as a program that only prints "Hello Bhai!" to the terminal.

I measured the compilation time using PowerShell's Measure-Command command. Compiling my C program took approximately 0.21 seconds.

I also uninstalled and freshly reinstalled VS Code, but I still notice a delay when running programs.

I would like to understand whether the delay is caused by Code Runner, terminal startup, the GCC execution process, or another configuration issue.

What troubleshooting steps can I use to identify the exact cause of this delay?

Thank you.

Developer technologies | Visual Studio | Other
Developer technologies | Visual Studio | Other

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.

0 comments No comments

1 answer

Sort by: Most helpful
  1. Bruno Caetano de Brito 245 Reputation points
    2026-10-18T00:06:39.06+00:00

    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 exit the 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. With showExecutionMessage on, 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:

    1. How long the delay is, in seconds.
    2. Your code-runner.runInTerminal value.
    3. 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 .exe several times: powershell
        gcc 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 exit the 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 (Output panel): no terminal is involved. With showExecutionMessage on, 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
      
      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:
      1. How long the delay is, in seconds.
      2. Your code-runner.runInTerminal value.
      3. 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:

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.