Low performance when creating arrays

This is a discussion on Low performance when creating arrays within the PHP General forums, part of the PHP Programming Forums category; Hello, I don't know if this is a normal situtation or it is a bug or I'm doing ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 06-15-2004
Ja
 
Posts: n/a
Default Low performance when creating arrays

Hello,
I don't know if this is a normal situtation or it is a bug or I'm
doing something wrong, but my application creates quite big arrays and
the php performance is quite low. Below I have made several tests,
which shows that creation time of multi-dimensional arrays is growing
rapidly. Is this a normal behaviour or maybe there is better solution
when making arrays. I use Windows XP, Apache, PHP 4.3.5. Thanks in
advance for any answer.

$test = Array();
$start = explode(" ", microtime());
for ($i = 0; $i < 100000; $i++) {
$test[] = "test";
}
$stop = explode(" ", microtime());
print ($stop[1]+$stop[0])-($start[1]+$start[0]);

-------Time: 0.24844598770142

$test = Array();
$start = explode(" ", microtime());
for ($i = 0; $i < 100000; $i++) {
$test[$i] = Array();
}
$stop = explode(" ", microtime());
print ($stop[1]+$stop[0])-($start[1]+$start[0]);

--------Time: 0.33644223213196


$test = Array();
$start = explode(" ", microtime());
for ($i = 0; $i < 100000; $i++) {
$test[$i] = Array(Array());
}
$stop = explode(" ", microtime());
print ($stop[1]+$stop[0])-($start[1]+$start[0]);

--------Time: 0.55727505683899


$test = Array();
$start = explode(" ", microtime());
for ($i = 0; $i < 100000; $i++) {
$test[$i] = Array(Array(), Array(), Array(), Array(Array()));
}
$stop = explode(" ", microtime());
print ($stop[1]+$stop[0])-($start[1]+$start[0])."<br/><br/>";

--------Time: 1.4375410079956
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 02:32 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0