Last active
February 22, 2016 20:59
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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