Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #15249

Optimize bash string handling?

From Alkis Georgopoulos <alkisg@gmail.com>
Newsgroups gnu.bash.bug
Subject Optimize bash string handling?
Date 2019-07-26 12:55 +0300
Message-ID <mailman.2297.1564149161.2688.bug-bash@gnu.org> (permalink)
References <73adb906-3594-8c38-c820-2bf00b295e22@gmail.com>

Show all headers | View raw


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

Back to gnu.bash.bug | Previous | Next | Find similar | Unroll thread


Thread

Optimize bash string handling? Alkis Georgopoulos <alkisg@gmail.com> - 2019-07-26 12:55 +0300

csiph-web