Skip to content

Instantly share code, notes, and snippets.

@mafredri
Last active January 12, 2017 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mafredri/93b01fd0384a737da213e6b9bba205a6 to your computer and use it in GitHub Desktop.
Save mafredri/93b01fd0384a737da213e6b9bba205a6 to your computer and use it in GitHub Desktop.
Quick performance test for setting a variable via capturing output to sub-shell vs a typeset in the running function
=== RUN test_bench_print_subshell_05
--- PASS: test_bench_print_subshell_05 (0.02s)
=== RUN test_bench_print_subshell_10
--- PASS: test_bench_print_subshell_10 (0.02s)
=== RUN test_bench_print_subshell_100
--- PASS: test_bench_print_subshell_100 (0.14s)
=== RUN test_bench_print_subshell_1000
--- PASS: test_bench_print_subshell_1000 (0.79s)
=== RUN test_bench_typeset_var_05
--- PASS: test_bench_typeset_var_05 (0.00s)
=== RUN test_bench_typeset_var_10
--- PASS: test_bench_typeset_var_10 (0.00s)
=== RUN test_bench_typeset_var_100
--- PASS: test_bench_typeset_var_100 (0.00s)
=== RUN test_bench_typeset_var_1000
--- PASS: test_bench_typeset_var_1000 (0.01s)
set_print() {
print "Hello world"
}
set_typeset() {
typeset -g "$1"="Hello world"
}
test_bench_print_subshell_05() {
local var
for i in {1..5}; do
var=$(set_print)
done
}
test_bench_print_subshell_10() {
local var
for i in {1..10}; do
var=$(set_print)
done
}
test_bench_print_subshell_100() {
local var
for i in {1..100}; do
var=$(set_print)
done
}
test_bench_print_subshell_1000() {
local var
for i in {1..1000}; do
var=$(set_print)
done
}
test_bench_typeset_var_05() {
local var
for i in {1..5}; do
set_typeset var
done
}
test_bench_typeset_var_10() {
local var
for i in {1..10}; do
set_typeset var
done
}
test_bench_typeset_var_100() {
local var
for i in {1..100}; do
set_typeset var
done
}
test_bench_typeset_var_1000() {
local var
for i in {1..1000}; do
set_typeset var
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment