Skip to content

Instantly share code, notes, and snippets.

@reorx
Last active February 22, 2016 20:59
Show Gist options
  • Save reorx/4b6b91a0db7807fc29b7 to your computer and use it in GitHub Desktop.
Save reorx/4b6b91a0db7807fc29b7 to your computer and use it in GitHub Desktop.
A snippet that helps you find the time cost of `source` in rc scripts
# Put these two functions at the top of your `.zshrc` or `.bashrc`
function _timestamp_ms() {
if [[ "$(uname)" == "Darwin" ]]; then
echo $(gdate +%s%3N)
else
echo $(date +%s%3N)
fi
}
# source with timer
function source() {
local ts=$(_timestamp_ms)
builtin source $1
local te=$(_timestamp_ms)
echo "$(($te - $ts))ms: source $1"
}
# eval with timer (only use if necessary)
#function eval() {
# local ts=$(_timestamp_ms)
# builtin eval $1
# local te=$(_timestamp_ms)
# echo "$(($te - $ts))ms: eval $1"
#}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment