[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: efficient way to use matched string in variable substitution
From: |
Greg Wooledge |
Subject: |
Re: efficient way to use matched string in variable substitution |
Date: |
Tue, 24 Aug 2021 09:24:35 -0400 |
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.
- efficient way to use matched string in variable substitution, L A Walsh, 2021/08/23
- Re: efficient way to use matched string in variable substitution, Greg Wooledge, 2021/08/23
- Re: efficient way to use matched string in variable substitution, L A Walsh, 2021/08/23
- Re: efficient way to use matched string in variable substitution, Greg Wooledge, 2021/08/23
- Re: efficient way to use matched string in variable substitution, Léa Gris, 2021/08/24
- Re: efficient way to use matched string in variable substitution, Greg Wooledge, 2021/08/24
- Re: efficient way to use matched string in variable substitution, Léa Gris, 2021/08/24
- Re: efficient way to use matched string in variable substitution, Mike Jonkmans, 2021/08/24
- Re: efficient way to use matched string in variable substitution,
Greg Wooledge <=
- Re: efficient way to use matched string in variable substitution, Mike Jonkmans, 2021/08/24
- Re: efficient way to use matched string in variable substitution, Léa Gris, 2021/08/24
- Re: efficient way to use matched string in variable substitution, Greg Wooledge, 2021/08/24
- Re: efficient way to use matched string in variable substitution, Mike Jonkmans, 2021/08/24
- Re: efficient way to use matched string in variable substitution, L A Walsh, 2021/08/24
- Re: efficient way to use matched string in variable substitution, Koichi Murase, 2021/08/24
Re: efficient way to use matched string in variable substitution, Oğuz, 2021/08/23