Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# StackOverflow.bash
$ (s() { echo $1; [[ $1 -le 0 ]] || s $(($1 - 1)); }; time s 6977)
Segmentation fault (core dumped)
$ (s() { echo $1; [[ $1 -le 0 ]] || s $(($1 - 1)); }; time s 6976)
real 0m10.097s
user 0m10.064s
sys 0m0.032s
$ (s() { local n=$1; echo $n; [[ $n -le 0 ]] || s $(($n - 1)); }; time s 6976)
real 0m16.249s
user 0m16.164s
sys 0m0.084s
$ (s() { local n=$1; shift; echo $n; [[ $n -le 0 ]] || s $(($n - 1)) "$@"; }; time s 6976)
real 0m18.549s
user 0m18.472s
sys 0m0.076s
$ (s() { local n=$1; shift; echo $n; [[ $n -le 0 ]] || s $(($n - 1)) "$@"; }; time s 6976 "$(openssl rand -hex -out /dev/stdout 1000)")
real 0m20.919s
user 0m20.780s
sys 0m0.112s
$ (s() { local n=$1; echo $n; [[ $n -le 0 ]] || s $(($n - 1)) "$@"; }; time s 6976)
real 1m19.046s
user 1m16.360s
sys 0m2.684s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment