On Tue, Aug 24, 2021 at 03:09:55PM +0200, Mike Jonkmans wrote: > This seems to be the fastest: > f12 () { [[ "$1" =~ ${1//?/(.)} ]]; local arr=( "${BASH_REMATCH[@]:1}" ); } > time for ((i=1; i<=10000; i++)); do f0 682390; done > real 0m0,296s > user 0m0,296s > sys 0m0,000s
Your CPU is a bit faster than mine, since none of mine (nor yours) go quite that fast on my computer, but you've written "f0" in your time command, not f12. On my computer, f6, f7 and f12 are all pretty much tied for "real" time, with variance between runs dictating which one comes out on top. > Nice thread, funny (but slow) solutions: > echo "abcdefg" | fold -w1 > echo "abcdefg" | grep -o . Especially when the original request was to avoid nonstandard external tools, using "grep -o" is definitely not the right answer.