In last post I wrote a about the differences between WSL and WSL 2. I also mentioned that WSL 2, even being inside a utility virtual machine in Hyper-V, delivers a better performance than WSL 1.

In this article we will kill the snake and show a stick. We will run a benchmark script in the same distro, but first running it on WSL 1 and then WSL 2 to compare this performance improvement. And also a plus, let’s compare the performance of the script result also in a container running on Docker Desktop.

Benchmark Script

I will use a nench benchmark script. It is a simple script that does some I/O, CPU and NETWORK tests. I made some changes to this script to run only the I/O test and the CPU test:

To do the tests I will run the command above, which will download the script gist and run in bash.

WSL 1

I downloaded Distro Ubuntu 18.04 on Windows Store.

The default WSL version of my Windows is 1. So let’s start testing using WSL 1. I ran the script and the result was:

Note the speeds of “dd: sequential write speed” 😢

WSL 2

For the WSL 2 tests I downloaded the Ubuntu Distro via Windows Store. As we can see in the image below, the “neofecth”, this version of the distro also runs Ubuntu 18.04, great for comparisons.

As the standard version of WSL on my Windows 10 is 1 we have to convert the distro to WSL 2:

For this I ran the command above on the power shell core, it is normal that this command takes a while. WSL has to “convert” all the root filesystem of the Linux distro into a VHDX, to run inside Hyper-V, and that takes a while.

After converting the distro we can then execute it and run the nench script:

Now notice the speed gain of “dd: sequential write speed” 😲

Also, note that we are using the MicroHobby Linux Kernel that we build in the last article 😎.

Docker Desktop

For testing with Docker Desktop I pulled and run the default Ubuntu image:

The latest tag from Ubuntu Dockerhub image is the LTS 18.04:

Great, we continue using the same version of Ubuntu for testing. And the result was:

Docker Desktop running Linux containers on Windows always with great performance 😍.

Conclusions

I gathered the result data in graphs for better comparison:

I/O AVG Speed –  Bigger better

It cannot be denied that the improvement in I/O performance is big between WSL 1 and 2. We had gain greater than 1400%, which is in line with what was announced by Microsoft of a 20x faster I/O performance in some cases with WSL 2.

The I/O speed compared to WSL 2 and the Docker container, started by Docker Desktop, as expected, showed very close results with a higher average speed for WSL 2.

CPU Speed – Smaller better

As for CPU usage, the results were not what I expected, I didn’t expect much difference. In my tests, WSL 1 got the better of doing hashing, compression and encryption in less time.

Remembering that my Windows was running other processes, recording video from the test to Youtube channel, audio, performing the composition through OBS Studio, running WSL 2, WSL 1 and Docker Desktop at the same time sharing CPU resources. This is by far not a good environment for CPU testing. But the result was at least interesting.

Final Considerations

O objetivo aqui foi um teste de performance bem rápido e simples, para uma primeira opinião sobre performance entre o WSL 1, 2  e o Docker Desktop rodando a mesma Distribuição Linux. Não tome os resultados aqui como absolutos! Mas contudo acho que foram resultados bem interessantes, conseguimos provar que realmente o WSL 2 entrega uma performance de I/O muuuito melhor.

The objective here was a very fast and simple performance test, for a first opinion on performance between WSL 1, 2 and Docker Desktop running the same Linux distribution. Do not take the results here as absolute! However, I think they were very interesting results, we managed to prove that WSL 2 really delivers a muuuch better I/O performance with Ubuntu Distro.

This content was produced in conjunction with the video on our Youtube channel (portuguese content):