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

Tip of the day: (@)...[(R)...] is equal to (@M)...:#... and faster by 18-21%



Hello,
I've discovered that following code:

found=( "${(@M)history:#(#i)*$~search_pattern*}" )

can be replaced by:

found=( "${(@)history[(R)(#i)*$~search_pattern*]}" )

and the speeds are: 215 ms vs. 175 ms, for "(#i)**" final pattern, ${#history[@]} == 89000, and typeset -U found (resolving to 18500 entries). Performing sequence of searches for word "h", "hi", "his", ..., "history" gives accumulated times 1271 ms vs. 1000 ms, difference is ~ 7*40ms, in check. Measured via zprof, by wrapping block of code with () { ... }.

I wonder if there are there any pitfalls in such replacement?

Best regards,

Sebastian Gniazdowski



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