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

Re: Example / partial fix for printf with math expressions



2024-02-24 14:40:41 +0000, Stephane Chazelas:
[...]
> With the one below using curlen / len[argp-args]:
[...]
> +			zlongval = (curarg) ? mathevali(metafy(curarg, curlen, META_HEAPDUP)) : 0;
[...]

That incur a performance penalty:

$ time zsh -c 'repeat 1000 printf %d 123_456+{1..10000}' > /dev/null
zsh -c 'repeat 1000 printf %d 123_456+{1..10000}' > /dev/null  6.07s user 0.46s system 99% cpu 6.544 total
$ time ./Src/zsh -c 'repeat 1000 printf %d 123_456+{1..10000}' > /dev/null
./Src/zsh -c 'repeat 1000 printf %d 123_456+{1..10000}' > /dev/null  9.97s user 0.62s system 99% cpu 10.602 total

The numbers end up being metafied (earlier), unmetafied by
printf, metafied again by printf here and that metafication
processed by the math handler I guess.

Maybe the performance could be *improved* instead if the
unmetafication could be skipped altogether in printf in those
cases?

-- 
Stephane




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