Skip to content

Instantly share code, notes, and snippets.

@jamiew
Last active December 19, 2019 16:52
Show Gist options
  • Save jamiew/81de7ec67c8a383e32b79a7e48b15c76 to your computer and use it in GitHub Desktop.
Save jamiew/81de7ec67c8a383e32b79a7e48b15c76 to your computer and use it in GitHub Desktop.
How I debugged my slow bash startup
# Start a new shell
... startup: 31
... git-completion: 113
... git-prompt: 41
... exports: 47
... rbenv: 216
... other scripts: 41
~$
print_timing(){
func_start=$1
func_label=$2
# func_end=$(date +%s%3N)
func_end=$(python -c 'from time import time; print int(round(time() * 1000))')
echo ... $func_label: $(( func_end-func_start ))
start=$func_end
}
start=$(python -c 'from time import time; print int(round(time() * 1000))')
print_timing $start "startup"
# some chunk of stuff
print_timing $start "first chunk"
# initialize my PS1 which got slow and hairy
print_timing $start "ps1"
# rbenv is pretty slow
print_timing $start "rbenv"
# load nvm because holy cow it's slow
print_timing $start "nvm"
# other scripts last
[[ -f ~/.bash_profile.local ]] && source ~/.bash_profile.local
[[ -f ~/.bash_aliases ]] && source ~/.bash_aliases
[[ -f ~/.bashrc ]] && source ~/.bashrc
print_timing $start "other scripts"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment