Spaceship-prompt: Optimization potential: use zsh modifier `:t` instead of `basename`

Created on 17 Jul 2017  Â·  3Comments  Â·  Source: denysdovhan/spaceship-prompt

The zsh :t modifier works like basename, but executes much faster (because it's a builtin).

I ran this a few times and saw an average speed increase of 50x.

~
➜ time (for k in `seq 1000`; do echo $(basename $foo) >/dev/null; done; )
( for k in `seq 1000`; do; echo $(basename $foo) > /dev/null; done; )  0.03s user 0.27s system 28% cpu 1.071 total

~
➜ time (for k in `seq 1000`; do echo $foo:t >/dev/null; done; )
( for k in `seq 1000`; do; echo $foo:t > /dev/null; done; )  0.01s user 0.00s system 85% cpu 0.019 total

~
➜ echo $foo && echo $(basename $foo) && echo $foo:t # basename & :t are equivalent
a/b/c
c
c
has-pr proposal

Most helpful comment

@nfischer Now we've separate LICENSE file in project 🎉

All 3 comments

Thank you @nfischer for this wonderful info.

Currently basename is used only in venv segment. Could you please send a PR ?

@sfarzy I would love to send a PR, but my company strongly prefers that any project I contribute to includes a LICENSE file in the top-level of the repo (they consider it to be safer legally-speaking than a one-liner in the README). Would that be something you and the maintainers (@denysdovhan) would be interested in adding?

@nfischer Now we've separate LICENSE file in project 🎉

Was this page helpful?
0 / 5 - 0 ratings

Related issues

AlecRust picture AlecRust  Â·  3Comments

doole picture doole  Â·  4Comments

gabrielpedepera picture gabrielpedepera  Â·  3Comments

ChadTaljaardt picture ChadTaljaardt  Â·  4Comments

JounQin picture JounQin  Â·  3Comments