From: Mikael Magnusson <mikachu@gmail.com>
To: nix@myproxylists.com
Cc: zsh-users@zsh.org
Subject: Re: Why large arrays are extremely slow to handle?
Date: Fri, 25 Mar 2011 01:46:03 +0100 [thread overview]
Message-ID: <AANLkTinqs3nre_5pX9CjVc8766k5JSRqs=0xNefoXUjA@mail.gmail.com> (raw)
In-Reply-To: <5c830d92034e61a01c96e6aa4d10798c.squirrel@gameframe.net>
On 25 March 2011 01:37, <nix@myproxylists.com> wrote:
> Tested on AMD Phenom(tm) II X6 1090T Processor 3.6GHz using one core.
>
> I think there's is a big flaw somewhere that causes the following:
>
> #!/bin/zsh
>
> emulate zsh
>
> TEST=()
>
> for i in {1..10000} ; do
>
> TEST+="$i" # append (push) to an array
>
> done
>
> --- 10K
> time ./bench
> real 0m3.944s
>
> --- 50K BOOOM! WTF?
>
> time ./bench
> real 1m53.321s
>
> Does not make much sense to me. Im also a PHP developer. Just for
> comparison, let's do the same with PHP.
>
> <?php
>
> $test = array();
>
> for ($i=1; $i < 50000; $i++) {
>
> $test[] = $i;
>
> }
>
> print_r($test);
>
> ?>
>
> --- 10K
>
> time php TEST_PHP
> real 0m0.011s
>
> --- 50K
>
> time php TEST_PHP
> real 0m0.025s
>
>
> Any ideas why it's extremely slow? I have need to use very large arrays
> (even over one million elements in a single array) but it's currently
> impossible due to the above.
The problem is not the array, but that you are handing 50000 arguments
to the for loop. With this optimization it "only" takes 5 seconds ;)
for (( i = 0; i < 10000; i++ )) { arr+=$i }
That said, you generally don't want to use large arrays in zsh, it will be slow.
--
Mikael Magnusson
next prev parent reply other threads:[~2011-03-25 0:46 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-03-25 0:37 nix
2011-03-25 0:46 ` Mikael Magnusson [this message]
2011-03-25 1:12 ` nix
2011-03-25 2:29 ` Bart Schaefer
2011-03-25 2:50 ` nix
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='AANLkTinqs3nre_5pX9CjVc8766k5JSRqs=0xNefoXUjA@mail.gmail.com' \
--to=mikachu@gmail.com \
--cc=nix@myproxylists.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).