Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- wtf_replace_old() { echo "$@" | sed -re 's/%F/4/g'; }
- substr_match() {
- local a b
- a=$1; shift; b=${#@}; a=${@#*$a}; a=${#a}
- [ $a -ne $b ]
- }
- wtf_match() { substr_match '%F' "$@"; }
- # dirty
- wtf_replace_new_v1() {
- local x="$@"
- while is_af_loose "$x"; do x=${x%%\%F*}4${x#*%F}; done
- echo "$x"
- }
- # kind of accurate
- wtf_replace_new_v2() {
- local x
- for x; do
- while is_af_loose "$x"; do x=${x%%\%F*}4${x#*%F}; done
- if substr_match ' ' "$x"; then echo "'$x'"; else echo "$x"; fi
- done
- }
- date --rfc-3339=ns
- for i in $(seq 1 10000); do
- wtf_replace_old "abc1337def%Fghi${i}klm%Fzyx"
- done > /dev/null
- date --rfc-3339=ns
- # 2018-04-19 01:36:38.196838148
- # 2018-04-19 01:36:47.792090732
- date --rfc-3339=ns
- for i in $(seq 1 10000); do
- wtf_replace_new_v1 "abc1337def%Fghi${i}klm%Fzyx"
- done > /dev/null
- date --rfc-3339=ns
- # 2018-04-19 01:36:47.792755513
- # 2018-04-19 01:36:48.047608340
- date --rfc-3339=ns
- for i in $(seq 1 10000); do
- wtf_replace_new_v2 "abc1337def%Fghi${i}klm%Fzyx"
- done > /dev/null
- date --rfc-3339=ns
- # 2018-04-19 01:36:48.048289043
- # 2018-04-19 01:36:48.362512638
- date --rfc-3339=ns
- for i in $(seq 1 50000); do
- wtf_replace_new_v1 "abc1337def%Fghi${i}klm%Fzyx"
- done > /dev/null
- date --rfc-3339=ns
- # 2018-04-19 01:36:48.363150082
- # 2018-04-19 01:36:49.632880751
- date --rfc-3339=ns
- for i in $(seq 1 50000); do
- wtf_replace_new_v2 "abc1337def%Fghi${i}klm%Fzyx"
- done > /dev/null
- date --rfc-3339=ns
- # 2018-04-19 01:36:49.633568684
- # 2018-04-19 01:36:51.242995435
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement