zsh-users
 help / color / mirror / code / Atom feed
From: <psprint@yahoo.com>
To: "zsh-users@zsh.org" <zsh-users@zsh.org>
Subject: Tip of the day: (@)...[(R)...] is equal to (@M)...:#... and faster by 18-21%
Date: Fri, 21 Oct 2016 08:59:56 +0000 (UTC)	[thread overview]
Message-ID: <536851559.167591.1477040396961@mail.yahoo.com> (raw)
In-Reply-To: <536851559.167591.1477040396961.ref@mail.yahoo.com>

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


       reply	other threads:[~2016-10-21  9:09 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <536851559.167591.1477040396961.ref@mail.yahoo.com>
2016-10-21  8:59 ` psprint [this message]
2016-10-21 16:20   ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=536851559.167591.1477040396961@mail.yahoo.com \
    --to=psprint@yahoo.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).