# Speed differences from vscode or as exe

**URL:** <https://ziggit.dev/t/speed-differences-from-vscode-or-as-exe/10914>\
**Category:** Explain\
**Created:** [July 11, 2025, 10:59am UTC](https://ziggit.dev/t/speed-differences-from-vscode-or-as-exe/10914 "2025-07-11T10:59:18Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![ericlang](https://ziggit.dev/user_avatar/ziggit.dev/ericlang/32/8515_2.png) [@ericlang](https://ziggit.dev/u/ericlang)\
**Post date:** [July 11, 2025, 10:59am UTC](https://ziggit.dev/t/speed-differences-from-vscode-or-as-exe/10914/1 "2025-07-11T10:59:19Z")

</div>

when running my zig chess program - which i finally ported from Rust - in releasefast mode in vscode i get these speeds.

```zig
perfttests: totalnodes: 5050230108, time 11.988s, nps 421242302
perft 7: nodes: 3195901860, time 6.021s, nps 530734817

```

when running the exe (also release fast mode) i get these:

```zig
perfttests: totalnodes: 5050230108, time 17.371s, nps 290727183
perft 7: nodes: 3195901860, time 9.879s, nps 323482246

```

what could cause the quite big differences?

It just uses the console for output and time measurements are always outside ‘print’ statements.  
(windows)

---

<div class="post-metadata">

**Author:** ![tsdtas](https://ziggit.dev/user_avatar/ziggit.dev/tsdtas/32/3512_2.png) [@tsdtas](https://ziggit.dev/u/tsdtas)\
**Post date:** [July 11, 2025, 11:13am UTC](https://ziggit.dev/t/speed-differences-from-vscode-or-as-exe/10914/2 "2025-07-11T11:13:03Z")

</div>

> time measurements are always outside ‘print’ statements.

What do you mean by this?

My first guess would be it’s got something to do with output buffering in the console, but this reads like you know it isn’t that.

---

<div class="post-metadata">

**Author:** ![ericlang](https://ziggit.dev/user_avatar/ziggit.dev/ericlang/32/8515_2.png) [@ericlang](https://ziggit.dev/u/ericlang)\
**Post date:** [July 11, 2025, 11:17am UTC](https://ziggit.dev/t/speed-differences-from-vscode-or-as-exe/10914/3 "2025-07-11T11:17:00Z")

</div>

Indeed something like this happens. I use a BufferedWriter.  
I thought that would be faster 🙂

I now see that when running as administrator the speeds are the same.  
Side effect is that my “print colored” to console does not work. it is all black and white. No ansi coloring.  
I need to remove console color printing anyway.

I wonder what is the optimal way to do things.

---

<div class="post-metadata">

**Author:** ![castholm](https://ziggit.dev/user_avatar/ziggit.dev/castholm/32/1330_2.png) [@castholm](https://ziggit.dev/u/castholm)\
**Post date:** [July 11, 2025, 11:28am UTC](https://ziggit.dev/t/speed-differences-from-vscode-or-as-exe/10914/4 "2025-07-11T11:28:45Z")

</div>

The native Windows console host is notorious for being slow and will incur overhead when scrolling the screen buffer. The vscode console might be optimized differently.

---

<div class="post-metadata">

**Author:** ![ericlang](https://ziggit.dev/user_avatar/ziggit.dev/ericlang/32/8515_2.png) [@ericlang](https://ziggit.dev/u/ericlang)\
**Post date:** [July 11, 2025, 11:32am UTC](https://ziggit.dev/t/speed-differences-from-vscode-or-as-exe/10914/5 "2025-07-11T11:32:13Z")

</div>

Yes but still strange it messes up my time-measuring in not-admin mode.

---

<div class="post-metadata">

**Author:** ![tsdtas](https://ziggit.dev/user_avatar/ziggit.dev/tsdtas/32/3512_2.png) [@tsdtas](https://ziggit.dev/u/tsdtas)\
**Post date:** [July 11, 2025, 11:44am UTC](https://ziggit.dev/t/speed-differences-from-vscode-or-as-exe/10914/6 "2025-07-11T11:44:45Z")

</div>

> I use a BufferedWriter.  
> I thought that would be faster 🙂

It _should_ be.

Normally when people report speed differences between running in an IDE console and running without it, it’s because the IDE will buffer the output more aggressively.

> I wonder what is the optimal way to do things.

I’m not super familiar with Windows-specific things, but honestly, I’d just avoid console output entirely, if you can. Console IO is almost always one of the slowest operations you can do, no matter how you do it.

I know an old trick is spinning up a thread to do the IO for you and enqueueing messages to that thread from your main program. That could maybe help.

---

<div class="post-metadata">

**Author:** ![Sze](https://ziggit.dev/user_avatar/ziggit.dev/sze/32/496_2.png) [@Sze](https://ziggit.dev/u/Sze)\
**Post date:** [July 11, 2025, 12:00pm UTC](https://ziggit.dev/t/speed-differences-from-vscode-or-as-exe/10914/7 "2025-07-11T12:00:45Z")

</div>

Get some better console/terminal for windows.

---

<div class="post-metadata">

**Author:** ![ericlang](https://ziggit.dev/user_avatar/ziggit.dev/ericlang/32/8515_2.png) [@ericlang](https://ziggit.dev/u/ericlang)\
**Post date:** [July 12, 2025, 9:36pm UTC](https://ziggit.dev/t/speed-differences-from-vscode-or-as-exe/10914/8 "2025-07-12T21:36:35Z")

</div>

I would not know how to do that.  
Somehow I need to use the operating system’s terminal I guess.

Furthermore: I should also implement the UCI protocol and feedback.  
The same way as all chess engines like Stockfish.

Running my current exe with adminstrators rights renders with a different font.  
But it is fast when doing my speed checks.

I really have no clue what is going on there.

It is quite ridiculous that my time measuring without any terminal / console output is slower.

---

<div class="post-metadata">

**Author:** ![ForeverZer0](https://ziggit.dev/user_avatar/ziggit.dev/foreverzer0/32/2443_2.png) [@ForeverZer0](https://ziggit.dev/u/ForeverZer0)\
**Post date:** [July 12, 2025, 9:59pm UTC](https://ziggit.dev/t/speed-differences-from-vscode-or-as-exe/10914/9 "2025-07-12T21:59:54Z")

</div>

> [@ericlang](#):
>
> I would not know how to do that.

There are alternatives to the default `cmd.exe` on Windows, no?  
I seem to remember that Alacritty had a Windows version, but I am confident that there are many others, even `powershell` would be an existing alternative that could be used to try and make sense of where the problem lies, and if it is indeed the fault of `cmd.exe`, or something else being overlooked.

---

<div class="post-metadata">

**Author:** ![Sze](https://ziggit.dev/user_avatar/ziggit.dev/sze/32/496_2.png) [@Sze](https://ziggit.dev/u/Sze)\
**Post date:** [July 12, 2025, 10:07pm UTC](https://ziggit.dev/t/speed-differences-from-vscode-or-as-exe/10914/10 "2025-07-12T22:07:29Z")

</div>

Even microsoft people have finally tried to improve upon their terrible existing terminals, supposedly this one should be a bit better then the old ones:

> **[Windows Terminal - Free download and install on Windows | Microsoft Store](https://apps.microsoft.com/detail/9n0dx20hk701?hl=en-US&gl=US)**
>
> The Windows Terminal is a modern, fast, efficient, powerful, and productive terminal application for users of command-line tools and shells like Command Prompt, PowerShell, and WSL. Its main features include multiple tabs, panes, Unicode and UTF-8...

But I can’t know for sure, I haven’t tried it.  
(Well below Casey seems to compare refterm against the preview of Windows Terminal, I am not sure if the final release has gotten better, but if not then maybe try to use some other third party terminal)

My solution is to never ever run windows as a user, but instead only in a vm if I need to test whether some program runs on windows.

So I can’t give you practical advice for using windows, I abandoned it almost two decades ago.

* * *

You also could try to use a profiler to find out exactly where it is slow, but before wasting time doing extensive analysis, I would try to find a way to run it where the problem disappears. The windows included terminals are notorious for being terrible from a performance standpoint.

---

<div class="post-metadata">

**Author:** ![ericlang](https://ziggit.dev/user_avatar/ziggit.dev/ericlang/32/8515_2.png) [@ericlang](https://ziggit.dev/u/ericlang)\
**Post date:** [July 12, 2025, 10:35pm UTC](https://ziggit.dev/t/speed-differences-from-vscode-or-as-exe/10914/11 "2025-07-12T22:35:10Z")

</div>

It is more from the Zig standpoint I would checkout what can be done.  
for printing output I just use `std.io.getStdOut().writer()`.  
When I compile on this window machine I get the default windows terminal window.

---

<div class="post-metadata">

**Author:** ![Sze](https://ziggit.dev/user_avatar/ziggit.dev/sze/32/496_2.png) [@Sze](https://ziggit.dev/u/Sze)\
**Post date:** [July 12, 2025, 11:26pm UTC](https://ziggit.dev/t/speed-differences-from-vscode-or-as-exe/10914/12 "2025-07-12T23:26:50Z")

</div>

Yeah and we are saying you should get a non-terrible terminal and execute your program from there, if the speed difference disappears then something about this

> [@ericlang](#):
>
> It just uses the console for output and time measurements are always outside ‘print’ statements.  
> (windows)

is probably incorrect.

Because something is causing a speed difference and it is likely something connected to io and the terminal that is used for output.

Alternatively you could also not print at all and instead log to a file.  
But I vaguely remember from refterm: [Refterm playlist](https://www.youtube.com/watch?v=hxM8QmyZXtg&list=PLEMXAbCVnmY6zCgpCFlgggRkrp0tpWfrn)

that even with file writing there where some performance bottlenecks with certain APIs, just don’t remember the details. (apparently something called fastpipes helps make it faster)

* * *

Well maybe you are even experiencing this (timestamped):  
 ![](https://ziggit.dev/uploads/default/optimized/2X/5/5f7f93179dbd67a5fb7130db13676d6f67e68651_2_690x388.jpeg)https://www.youtube.com/embed/99dKzubvpKE?feature=oembed&wmode=opaque&list=PLEMXAbCVnmY6zCgpCFlgggRkrp0tpWfrn&start=644

---

<div class="post-metadata">

**Author:** ![ericlang](https://ziggit.dev/user_avatar/ziggit.dev/ericlang/32/8515_2.png) [@ericlang](https://ziggit.dev/u/ericlang)\
**Post date:** [August 16, 2025, 7:12pm UTC](https://ziggit.dev/t/speed-differences-from-vscode-or-as-exe/10914/13 "2025-08-16T19:12:45Z")

</div>

Yes probably! “Bypass standard IO” I am not going to do…

Another thing was in my main function:

```zig
// version 1
fn main() !void
{
    run_chess_speed_test(); // 1200 million nodes per second
}

/// version 2
fn main() !void
{
    run_chess_speed_test(); // 850 million nodes per second
    run_io_loop();
}

```

which I think is very strange.

Running windows terminal as administrator also speeds up quite a lot, which is insane in my opinion. Testing other chess engines (Stockfish, Gigantue) I noticed they were a bit slower as well.

Questions remain. What can I do in Zig to maximize the speed, io not interfering too much.  
Of course outputting something to the terminal messes up the cpu-cache etc. so probably there is nothing to do.

Curious how things will be in zig 0.15 too.

---

<div class="post-metadata">

**Author:** ![Sze](https://ziggit.dev/user_avatar/ziggit.dev/sze/32/496_2.png) [@Sze](https://ziggit.dev/u/Sze)\
**Post date:** [August 16, 2025, 9:39pm UTC](https://ziggit.dev/t/speed-differences-from-vscode-or-as-exe/10914/14 "2025-08-16T21:39:59Z")

</div>

I think you need to start using more tooling for example sampling and tracing profilers.  
Maybe try to use tracy.

I think if you want to make progress you need to make more detailed measurements, better benchmarking tools, or profilers can help with that.

If the speed test measurement itself doesn’t have a problem, then there still could be a number of things causing different throughputs (ideally you would measure more than just throughput):

- program being scheduled and switched between different cpus mid execution, causing varying additional latency added by the OS (should be visible with profiling tools)  
fix: pin the program on a single core, or use tools that distinguish between wall clock and actual runtime
- running the program on cpus with varying clockspeeds  
fix: set the cpu clock speed to a fixed value, during program execution
- address space layout randomization, causing different things in the program to be slow  
fix: have enough independent runs so that the variance between different runs gets washed out through determining the mean ([ideally the profiler would re-randomize](https://www.youtube.com/watch?v=r-TLSBdHe1A) the layout during the run of the program)

For benchmarks you also want a tool that is able to record system calls, cache misses, branch misses etc. (so that you have an easier time spotting possible causes)

If you find good tools to use under windows you can also add those to the tools section of this doc, or add a comment:

> [@Benchmarking](https://ziggit.dev/t/benchmarking/4675):
>
> What is a benchmark? A benchmark is an automated way to methodically collect measurements, possibly using those results in more or less automated ways. Benchmarking vs Profiling The basic distinction between benchmarking and profiling, is that benchmarking measures how: how fast is a routine, how much memory does it allocate. Profiling is concerned with where: how much time within a process is spent on which functions, and which lines, and the same for allocations, syscalls, and other resourc…

Some people on random forum posts I found, have mentioned [Windows Performance Analyzer | Microsoft Learn](https://learn.microsoft.com/en-us/windows-hardware/test/wpt/windows-performance-analyzer) so that is another thing you could try, I am not on windows so I haven’t used it.

---

<div class="post-metadata">

**Author:** ![dimdin](https://ziggit.dev/user_avatar/ziggit.dev/dimdin/32/1457_2.png) [@dimdin](https://ziggit.dev/u/dimdin)\
**Post date:** [August 17, 2025, 7:36am UTC](https://ziggit.dev/t/speed-differences-from-vscode-or-as-exe/10914/15 "2025-08-17T07:36:11Z")

</div>

I just added a few more tools in the [benchmarking](https://ziggit.dev/t/benchmarking/4675) page.  
For Windows, there is `PerfView`. It is inspired by linux perf and is open sourced by Microsoft. It is widely used in windows because it works for .net applications as opposed to the much more complex Windows Performance Analyzer.  
For perf, I added some links like Julia Evans Zine: Profiling and Tracing with Perf, and the Gnome sysperf (similar to hotspot).

---

<div class="post-metadata">

**Author:** ![ericlang](https://ziggit.dev/user_avatar/ziggit.dev/ericlang/32/8515_2.png) [@ericlang](https://ziggit.dev/u/ericlang)\
**Post date:** [August 23, 2025, 8:36am UTC](https://ziggit.dev/t/speed-differences-from-vscode-or-as-exe/10914/16 "2025-08-23T08:36:50Z")

</div>

Thanks for the answers. I never did any “official” benchmarking.  
I’ll have to dive into that.

I noticed that with Zig 0.15.1 the speeddifference between running the console in admin mode and non admin mode are almost gone.
