Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Why large arrays are extremely slow to handle?
- X-seq: zsh-users 15892
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: nix@xxxxxxxxxxxxxxxx
- Subject: Re: Why large arrays are extremely slow to handle?
- Date: Fri, 25 Mar 2011 01:46:03 +0100
- Cc: zsh-users@xxxxxxx
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=HXfpQKE54wOBP7ZjBl0pCr++PoNCNOf/u6EnDrvZSfg=; b=rfMIbcL4m0UtQZTDCZLXa+8katnhL5YQZiwM+9IBCD3mnooABARzweq4FEtEi25pB4 YbLIebCpTcL1wMhi0YRlwZ+ORY1WKYHMA+BenP9LxtKYFPYwlsI6pImclQUZbUtVd6o4 +Xl7Jy/nKHWepUDRAEteWO0uddzzFaWliu5MM=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; b=uLRUGiv5+fFIfD+Gtx/FeIPi7/UPY2+bAjmCQn1FwwyA3GZvnCnYq4EL19+r6nivr6 NfKfvAbLrRKnBngJy7nNcUx9Hm3TNZL9OPUUBWbLArF30rONloS9D3/cmiFrCCou7ULd lTRmrwHv6e2FaVh39e/FdZbU56fA/LHKJVjPM=
- In-reply-to: <5c830d92034e61a01c96e6aa4d10798c.squirrel@gameframe.net>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <5c830d92034e61a01c96e6aa4d10798c.squirrel@gameframe.net>
On 25 March 2011 01:37, <nix@xxxxxxxxxxxxxxxx> 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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author