[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Optimize bash string handling?

From: Alkis Georgopoulos
Subject: Optimize bash string handling?
Date: Fri, 26 Jul 2019 12:55:18 +0300
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0

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

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.

Alkis Georgopoulos

reply via email to

[Prev in Thread] Current Thread [Next in Thread]