While handling some big strings, I noticed that bash is a lot slower
than other shells like dash, posh and busybox ash.
I came up with the following little benchmark and results.
While the specific benchmark isn't important, maybe some developer
would like to use it to pinpoint and optimize some internal bash
function that is a lot slower than in other shells?

# Avoid UTF-8 complications
export LANG=C

# Run the following COMMANDs with `time bash -c`
# or `time busybox ash -c`
# The time columns are in seconds, on an i5-4440 CPU

ASH BASH  COMMAND
0.1  0.1  printf "%100000000s" "." >/dev/null
0.7  1.1  x=$(printf "%100000000s" ".")
0.8  2.4  x=$(printf "%100000000s" "."); echo ${#x}
0.9  3.7  x=$(printf "%100000000s" "."); echo ${#x}; echo ${#x}

At this point I think it's safe to assume that just calculating the
100MB string length in bash needs 1.3 secs, while in ash 0.1 secs.

Similar differences may be observed in simple assignments like y=$i$x.
If anyone replies, please CC me as I'm not in the list.

Thanks,
Alkis Georgopoulos

Reply via email to