tarjoilija / zgen

A lightweight and simple plugin manager for ZSH
BSD 2-Clause "Simplified" License
1.49k stars 98 forks source link

Replace basename and dirname with parameter expansion #85

Closed itiut closed 5 years ago

itiut commented 7 years ago

This replaces basename and dirname with equivalent parameter expansions (${var:t} and ${var:h} respectively) mainly for speed.

For benchmarking I measured zsh startup time with the following .zshrc (though this is an extreme case).

# .zshrc
for i in {1..100}; do
  source ~/.zgen/zgen.zsh
done

As a result, startup time was reduced by about 40%.

# before
$ /usr/bin/time zsh -cli 'exit 0'
        1.58 real         0.58 user         0.86 sys

# after
$ /usr/bin/time zsh -cli 'exit 0'
        0.94 real         0.37 user         0.56 sys
Tuurlijk commented 7 years ago

Nice one!

Did you know that zsh has a builtin called repeat?

You can do:

repeat 100 {source ~/.zgen/zgen.zsh}

tarjoilija commented 5 years ago

Thank you.