Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.