I have been testing my WSL1 environment running Ubuntu 18.04 with a new WSL2 environment running Ubuntu 20.04 on a laptop with a 2 core i5 and 16GB RAM running Windows 10, version 2004, build 19041.388. The filesystem used is a standard Windows NTFS on an SSD drive.
The older environment performs much better. I wondered if others had noticed the same? Would the OS change alone account for the difference?
WSL2 was billed as having higher performance and I saw a quote of "up to 20x faster compared to WSL 1 when unpacking a zipped tarball". That's not been my experience, as can be seen below.
I recognise that I am not comparing like with like as the OS has changed but I am still surprised. I expect a lot of people moving from WSL1 to WSL2 will also upgrade from 18.04 LTS to 20.04 LTS.
Running the following code
#!/bin/bash +x
#1
time ls -altr > /dev/null
#2
time head -c 50M < /dev/urandom > /dev/null
#3
time head -c 50M < /dev/urandom > genran4u.sh.$WSL_DISTRO_NAME
#4
time for i in {a..e};do
echo delthis.$i
tr -dc 'a-z\n' < /dev/urandom \
| head -c50M > delthis.$i
done
rm delthis.tgz
#5
time tar -zcvf delthis.tgz delthis.{a..e}
rm delthis.{a..e}
#6
time tar -zxvf delthis.tgz
on the 2 environments running
$ time ./bench_wsl_a.sh 2>&1 | grep real
gives
Output comparison:
WSL1 + 18.04 | WSL2 + 20.04
|
#1: real 0m0.285s | real 0m3.356s
#2: real 0m0.106s | real 0m0.199s
#3: real 0m0.214s | real 0m2.375s
#4: real 0m10.829s | real 0m23.823s
#5: real 0m13.055s | real 0m14.721s
#6: real 0m3.676s | real 0m6.651s
Totals
real 0m28.275s | real 0m51.229s
The 'Legacy' version is consistently faster.