Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Why large arrays are extremely slow to handle?
- X-seq: zsh-users 15891
- From: nix@xxxxxxxxxxxxxxxx
- To: zsh-users@xxxxxxx
- Subject: Why large arrays are extremely slow to handle?
- Date: Fri, 25 Mar 2011 02:37:45 +0200
- Importance: Normal
- 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
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.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author