note 94179 added to class.splfixedarray
| From: | nairbvATyahooDOTcom at osu1 dot php dot net | Date: | Wed, 21 Oct 2009 09:08:48 +0000 |
| Subject: | note 94179 added to class.splfixedarray | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-161933@lists.php.net to get a copy of this message | ||
Though, object creation overhead means this method is slower for small arrays.
for example, if the other posters benchmark script is changed to a more realistic:
<?php
$elements = 20;
for($size = 1000; $size < 50000000; $size *= 2) {
echo PHP_EOL . "Testing size: $size" . PHP_EOL;
for($s = microtime(true), $i = 0; $i < $size; $i++) {
for($j=0,$container=array();$j < $elements; $j++ ) {
$container[$i] = NULL;
}
}
echo "Array(): " . (microtime(true) - $s) . PHP_EOL;
for($s = microtime(true), $i = 0; $i < $size; $i++) {
for( $j=0,$container=new SplFixedArray($elements);$j<$elements;$j++) {
$container[$i] = NULL;
}
}
echo "SplArray(): " . (microtime(true) - $s) . PHP_EOL;
}
we get:
Testing size: 1000
Array(): 0.0030221939086914
SplArray(): 0.0041899681091309
Testing size: 2000
Array(): 0.0060598850250244
SplArray(): 0.0083701610565186
Testing size: 4000
Array(): 0.012003898620605
SplArray(): 0.016681909561157
Testing size: 8000
Array(): 0.024173021316528
SplArray(): 0.033347129821777
Testing size: 16000
Array(): 0.048118829727173
SplArray(): 0.066897869110107
Testing size: 32000
Array(): 0.096546173095703
SplArray(): 0.13370203971863
Testing size: 64000
Array(): 0.1932430267334
SplArray(): 0.26755595207214
Testing size: 128000
Array(): 0.38473010063171
SplArray(): 0.5374698638916
Testing size: 256000
Array(): 0.77228307723999
SplArray(): 1.0708079338074
Testing size: 512000
Array(): 1.5438990592957
SplArray(): 2.1406710147858
Testing size: 1024000
Array(): 3.0910761356354
SplArray(): 4.3108429908752
Testing size: 2048000
Array(): 6.1561989784241
SplArray(): 8.612802028656
......
----
Server IP: 69.147.83.197
Probable Submitter: 119.75.43.62
----
Manual Page -- http://www.php.net/manual/en/class.splfixedarray.php
Edit -- https://master.php.net/note/edit/94179
Del: integrated -- https://master.php.net/note/delete/94179/integrated
Del: useless -- https://master.php.net/note/delete/94179/useless
Del: bad code -- https://master.php.net/note/delete/94179/bad+code
Del: spam -- https://master.php.net/note/delete/94179/spam
Del: non-english -- https://master.php.net/note/delete/94179/non-english
Del: in docs -- https://master.php.net/note/delete/94179/in+docs
Del: other reasons-- https://master.php.net/note/delete/94179
Reject -- https://master.php.net/note/reject/94179
Search -- https://master.php.net/manage/user-notes.php