zsh-users
 help / color / mirror / code / Atom feed
From: nix@myproxylists.com
To: "Mikael Magnusson" <mikachu@gmail.com>
Cc: zsh-users@zsh.org
Subject: Re: Why large arrays are extremely slow to handle?
Date: Fri, 25 Mar 2011 03:12:06 +0200	[thread overview]
Message-ID: <446d1efa4ce9f5b6bc6dc8782050cb3f.squirrel@gameframe.net> (raw)
In-Reply-To: <AANLkTinqs3nre_5pX9CjVc8766k5JSRqs=0xNefoXUjA@mail.gmail.com>

> 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
>

There problem is the array. I tried it also on a DUAL X5450 XEON machine,
terribly slow on it as well while using ZSH.

I would love to have a fix. I just coded subnet generator in ZSH and
noticed when i started to generate larger IP-ranges, things started to go
very slowly :(

Mikael, try this with provided example:

arr=( $(print -r -- ${(u)=arr}) ) # List only unique elements in an array

It's terrible slow as well with 50K elements, the problem is nothin but
the array handling.

#!/bin/zsh

emulate zsh

TEST=()

for (( i = 0; i < 50000; i++ )) ; do

TEST+="$i"

done

time ./BENC
real    1m54.353s

Not difference at all to "for {1..50000}" ;)



  reply	other threads:[~2011-03-25  1:12 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
2011-03-25  1:12   ` nix [this message]
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=446d1efa4ce9f5b6bc6dc8782050cb3f.squirrel@gameframe.net \
    --to=nix@myproxylists.com \
    --cc=mikachu@gmail.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).