0

I have a Windows 10 system with WSL v2 Ubuntu enabled. If I run bash from Windows to call a programm installed on Linux, it is very slow (500-800ms) for even a trivial command.

I used Measure-Command in PowerShell to time it:

PS C:\Users\thoma\Desktop> Measure-Command { bash -c "echo Hello" }

...
TotalMilliseconds : 655,8447

In comparision cmd takes a fraction:

PS C:\Users\thoma\Desktop> Measure-Command { cmd /c echo Hello }

...
TotalMilliseconds : 17,5062

Any ideas why this is so slow? I deactivated any anti virus software.

2
  • 1
    For a comparable result you should not call bash from within a PowerShell. Calling cmd.exe is like a local phone call and calling something from WSL is like a far call to a different continent.
    – Robert
    Commented Jul 16, 2021 at 21:31
  • That makes sense, but I feel that it used to be much quicker. Could anyone else execute these two calls and share their results?
    – tomfroehle
    Commented Jul 16, 2021 at 21:57

1 Answer 1

0

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .