Skip to content

Instantly share code, notes, and snippets.

@arren-ru
Last active August 7, 2024 15:59
Show Gist options
  • Save arren-ru/05b62b6129b3bb123f9e1a248cb1d193 to your computer and use it in GitHub Desktop.
Save arren-ru/05b62b6129b3bb123f9e1a248cb1d193 to your computer and use it in GitHub Desktop.
Benchmark BASH serialization
#!/usr/bin/env bash
declare -A output sample=(
[id]="969AEF26-6D33-475A-982B-27EC880A2495"
[name]="some_name"
[prop]="property with spaces"
[level]="lower"
[production]="no"
[env]="staging"
)
marshall_declare() {
for i in {1..1000}; do
local data=$(declare -p sample)
eval "output=${data#*=}"
done
}
marshall_native() {
for i in {1..1000}; do
eval "output=(${sample[*]@K})"
done
}
echo >&2 Declare serialization
time marshall_declare
echo >&2 Native serialization
time marshall_native
# Declare serialization
# real 0m0.857s
# user 0m0.620s
# sys 0m0.281s
# Native serialization
# real 0m0.067s
# user 0m0.067s
# sys 0m0.000s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment