[prev in list] [next in list] [prev in thread] [next in thread]
List: busybox
Subject: performance: ${str#????} vs ${str:4}
From: Alin Mr <almr.oss () outlook ! com>
Date: 2021-07-28 7:08:58
Message-ID: AM8PR08MB57957BD2786B12ED873641ECF7EA9 () AM8PR08MB5795 ! eurprd08 ! prod ! outlook ! com
[Download RAW message or body]
Surprisingly, string matching is faster than substring-ing.
# s is ':' repeated (6 * 2^i) times
s=$(s=::::::; i=12; while [ $i -gt 0 ]; do i=$((i-1)); s="$s$s"; done; echo "$s") \
hyperfine -w2 -S bbox-master/sh 'while [ "$s" ]; do s=${s#????}; done' 'while [ "$s" \
]; do s=${s:4}; done'
Summary
'while [ "$s" ]; do s=${s#????}; done' ran
1.16 ± 0.00 times faster than 'while [ "$s" ]; do s=${s:4}; done'
The slowdown doesn't depend much on the skip parameter -- ${s:1} as well as ${s:16} \
are slower than corresponding pattern matches. There are jump points if $s gets much \
longer or much shorter.
I'm curious -- the SUBSTR code seems to check for quotes and CTLESC in vstr, so I \
guess... it can substring in unprocessed (shell) strings? When does this come into \
play -- it's not like one can write ${"a\\bc":2}? \
_______________________________________________ busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic