zsh-workers
 help / color / mirror / code / Atom feed
* Performance tests of quoting and dequoting, printf -v turned out slow
@ 2018-03-09  6:22 Sebastian Gniazdowski
  2018-03-09 13:23 ` Stephane Chazelas
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Sebastian Gniazdowski @ 2018-03-09  6:22 UTC (permalink / raw)
  To: zsh-workers

[-- Attachment #1: Type: text/plain, Size: 668 bytes --]

Hello
Two scripts:

- short.txt
Test of quoting, (q)-flag vs. printf -v output '%q '
result: 35 ms vs. 26.6 sec

- Q_short.txt – test of dequoting, (Q)-flag vs. eval "str=$quoted"
result: 25 ms vs. 77 ms

I've compared "printf -v" code to Bash 4.4 and it yields 227 ms there, so much better than 26.6 sec. So while "Bash can serialize/deserialize too, let's compare speed of this method" is interesting thing and I share, performance of "printf -v" on Zsh is troubling. Any idea from where it comes from and if it can be improved?

https://github.com/zdharma/hacking-private/tree/master/quoting

--  
Sebastian Gniazdowski
psprint /at/ zdharma.org

[-- Attachment #2: Q_short.txt --]
[-- Type: text/plain, Size: 574 bytes --]

# This file should be sourced.
# It tests performance of dequoting, (Q) vs eval "s=$quoted"

INPUT='ice as"program" pick"$ZPFX/bin/prll_(qer|bfr)" src"prll.sh" make"install PREFIX=$ZPFX"'
INPUT="${(q)INPUT}"

# The same output
eval "str=$INPUT"
print -r -- "$str"
print -r -- "${(Q)INPUT}"

Qflag() {
    local OUTPUT
    repeat 50000; do
        OUTPUT="${(Q)INPUT}"
    done
}

evl() {
    local OUTPUT
    repeat 50000; do
        eval "OUTPUT=$INPUT"
    done
}

typeset -F2 SECONDS=0
Qflag
print "(Q)-flag result: $SECONDS"

SECONDS=0
evl
print "eval result: $SECONDS"

[-- Attachment #3: short.txt --]
[-- Type: text/plain, Size: 555 bytes --]

# This file should be sourced.
# It tests performance of quoting, (q) vs printf '%q '.

INPUT='ice as"program" pick"$ZPFX/bin/prll_(qer|bfr)" src"prll.sh" make"install PREFIX=$ZPFX"'

# The same output
printf '%q ' "$INPUT"
print
print -r -- "${(q)INPUT}"

qflag() {
    local OUTPUT
    repeat 10000; do
        OUTPUT="${(q)INPUT}"
    done
}

prtf() {
    local OUTPUT
    repeat 10000; do
        printf -v OUTPUT '%q ' "$INPUT"
    done
}

typeset -F3 SECONDS=0
qflag
print "(q)-flag result: $SECONDS"

SECONDS=0
prtf
print "printf result: $SECONDS"

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2018-03-13 11:41 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-09  6:22 Performance tests of quoting and dequoting, printf -v turned out slow Sebastian Gniazdowski
2018-03-09 13:23 ` Stephane Chazelas
     [not found] ` <etPan.5aa28b1e.77e79f33.159ee@AirmailxGenerated.am>
2018-03-09 13:39   ` Sebastian Gniazdowski
2018-03-09 14:53     ` Stephane Chazelas
2018-03-10  8:36       ` Sebastian Gniazdowski
2018-03-10 15:03         ` Stephane Chazelas
     [not found]         ` <etPan.5aa3f656.1efba338.159ee@AirmailxGenerated.am>
2018-03-10 16:53           ` Sebastian Gniazdowski
2018-03-10 15:40 ` Oliver Kiddle
2018-03-11  8:33   ` Bart Schaefer
2018-03-13 11:28     ` Sebastian Gniazdowski

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).