|
| 1 | +--- |
| 2 | +title: "Shell Speedup" |
| 3 | +date: 2025-01-21T21:16:21+01:00 |
| 4 | +--- |
| 5 | + |
| 6 | +https://work.lisk.in/2020/11/20/even-faster-bash-startup.html#completions |
| 7 | + |
| 8 | +https://danpker.com/posts/faster-bash-startup/ |
| 9 | + |
| 10 | + |
| 11 | +## Benchmark bash startup speed by hyperfine |
| 12 | + |
| 13 | +```shell |
| 14 | +hyperfine 'bash -i' |
| 15 | +``` |
| 16 | + |
| 17 | +Benchmark 1: bash -i |
| 18 | + Time (mean ± σ): 262.5 ms ± 29.4 ms [User: 156.9 ms, System: 74.1 ms] |
| 19 | + Range (min … max): 249.0 ms … 345.9 ms 10 runs |
| 20 | + |
| 21 | + |
| 22 | +``` |
| 23 | +$ source ~/.bash_profile |
| 24 | +bash_exports: 0.015 |
| 25 | +bash_aliases: 0.000 |
| 26 | +bash_autocompletion: 0.000 |
| 27 | +bash_colors: 0.000 |
| 28 | +bash_functions: 0.000 |
| 29 | +bash_options: 0.000 |
| 30 | +bash_prompt: 0.024 |
| 31 | +bash.local: 0.000 |
| 32 | +conda: 0.000 |
| 33 | +``` |
| 34 | + |
| 35 | + |
| 36 | +Benchmark 1: bash --login |
| 37 | + Time (mean ± σ): 45.8 ms ± 2.0 ms [User: 16.3 ms, System: 20.7 ms] |
| 38 | + Range (min … max): 42.0 ms … 52.8 ms 57 runs |
| 39 | + |
| 40 | +`eval $(/opt/homebrew/bin/brew shellenv)` would add ~ 27 ms delay |
| 41 | + |
| 42 | +`bash_prompt` add ~ 20 ms |
| 43 | + |
| 44 | + |
| 45 | +bash_exports: 0.001 s |
| 46 | +bash_aliases: 0.000 s |
| 47 | +bash_autocompletion: 0.029 s |
| 48 | +bash_colors: 0.000 s |
| 49 | +bash_functions: 0.000 s |
| 50 | +bash_options: 0.000 s |
| 51 | +bash_prompt: 0.022 s |
| 52 | +bash.local: 0.000 s |
| 53 | +conda: 0.003 |
| 54 | + |
| 55 | + |
| 56 | +## Autocompletion diff: 140 ms on load up |
| 57 | + |
| 58 | +myMacbook:~ wyq977$ hyperfine 'bash --login' |
| 59 | +Benchmark 1: bash --login |
| 60 | + Time (mean ± σ): 12.9 ms ± 0.8 ms [User: 5.0 ms, System: 4.9 ms] |
| 61 | + Range (min … max): 11.7 ms … 16.8 ms 187 runs |
| 62 | + |
| 63 | +myMacbook:~ wyq977$ hyperfine 'bash -i' |
| 64 | +Benchmark 1: bash -i |
| 65 | + Time (mean ± σ): 160.2 ms ± 2.4 ms [User: 120.7 ms, System: 33.2 ms] |
| 66 | + Range (min … max): 157.3 ms … 164.9 ms 17 runs |
| 67 | + |
| 68 | +## ZSH is much faster? |
| 69 | + |
| 70 | +myMacbook:~ wyq977$ hyperfine 'zsh --login' |
| 71 | +Benchmark 1: zsh --login |
| 72 | + Time (mean ± σ): 4.4 ms ± 0.6 ms [User: 1.3 ms, System: 1.8 ms] |
| 73 | + Range (min … max): 3.2 ms … 7.2 ms 311 runs |
| 74 | + |
| 75 | + |
| 76 | +❯ hyperfine 'zsh -cli exit' |
| 77 | +Benchmark 1: zsh -cli exit |
| 78 | + Time (mean ± σ): 72.8 ms ± 1.5 ms [User: 26.2 ms, System: 30.2 ms] |
| 79 | + Range (min … max): 69.7 ms … 76.5 ms 39 runs |
| 80 | + |
| 81 | +❯ hyperfine '/opt/homebrew/bin/bash -cli exit' |
| 82 | +Benchmark 1: /opt/homebrew/bin/bash -cli exit |
| 83 | + Time (mean ± σ): 77.0 ms ± 3.4 ms [User: 37.4 ms, System: 27.3 ms] |
| 84 | + Range (min … max): 73.9 ms … 93.6 ms 31 runs |
| 85 | + |
0 commit comments