Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Performance tests of quoting and dequoting, printf -v turned out slow

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

I can't reproduce speeds that bad from printf -v. I get a factor of 4 at
most vs. (q).

What may affect things is whether or not zsh was built to use
open_memstream from libc. FreeBSD and GNU libc have open_memstream. If
you're using some other OS or an alternative libc on Linux it might be
using a temporary file. Having /tmp on tmpfs may help.

Rearranging printf to use sprintf() might make it faster but calculating
suitable buffer sizes is not necessarily easy given that the format
is essentially arbitrary. It was originally written without printf -v
being a feature: print -s and -z combined with -f were never going to be
performance critical. Being able to do printf to a stdio stream keeps
the code simpler.


Messages sorted by: Reverse Date, Date, Thread, Author