If you have seen an increase in the startup time recently, did anything change in your ~/.profile
or ~/.bashrc
(or any other startup config)?
Using bash
to start up WSL is a bit outdated, so I'm going to use the wsl
command for the purposes of the following examples. It's more flexible, at the very least.
You don't mention in your question whether or not WSL was running when you executed your one-and-only Measure-Command
against it. Let's do it several times, with a cold start and a warm start:
First, I terminate the WSL instance with wsl --terminate Ubuntu
and confirm it is stopped with wsl -l -v
.
Then, Measure-Command { wsl -e bash -noprofile -norc -c "echo Hello" }
. This keeps bash
from reading the startup config.
My results on a fresh start of WSL were consistently around 280ms. A second run with WSL already running was between 96ms-100ms.
Your cmd
example, for me, was around 17ms, with one outlier being 34ms. Of course, CMD is pretty much always loaded in Windows, since it's used for so much. So there's never (to my knowledge) any "cold startup time" for it.
Also, for reference, from within WSL, I used hyperfine
to test the same (and converse):
> hyperfine 'bash -noprofile -norc -c "echo Hello"'
Benchmark #1: bash -noprofile -norc -c "echo Hello"
Time (mean ± σ): 1.2 ms ± 0.6 ms [User: 1.2 ms, System: 0.1 ms]
Range (min … max): 0.8 ms … 5.2 ms 1660 runs
> hyperfine 'powershell.exe -NoProfile -c "echo Hello"'
Benchmark #1: powershell.exe -NoProfile -c "echo Hello"
Time (mean ± σ): 263.5 ms ± 6.6 ms [User: 5.6 ms, System: 0.3 ms]
Range (min … max): 256.6 ms … 279.5 ms 11 runs
> hyperfine 'cmd.exe -c "echo Hello"'
Benchmark #1: cmd.exe -c "echo Hello"
Time (mean ± σ): 27.9 ms ± 2.4 ms [User: 3.6 ms, System: 0.4 ms]
Range (min … max): 23.7 ms … 34.0 ms 98 runs
> hyperfine 'pwsh.exe -NoProfile -c "echo Hello"'
Benchmark #1: pwsh.exe -NoProfile -c "echo Hello"
Time (mean ± σ): 461.1 ms ± 7.7 ms [User: 5.6 ms, System: 1.4 ms]
Range (min … max): 453.9 ms … 476.5 ms 10 runs