note 39209 added to function.array-push
| From: | skiflyer at rn2 dot php dot net | Date: | Tue, 20 Jan 2004 21:05:07 +0000 |
| Subject: | note 39209 added to function.array-push | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-63904@lists.php.net to get a copy of this message | ||
However, don't forget that array_push() does more than [], it also performs a count and returns
the value.
Modifying your code ever so slightly (see below), this puts array_push in the lead (not
suprisingly). So my conclusion would be that if I care about the number of elements in the array,
then I'd use array_push(), if I don't (which is usually the case), then I'd use the
[] method.
Results...
[] method: 0.34943199
push method: 0.31505919
difference: -0.03437280
Modified section of code...
$s_test_begin = FullMicroTime();
for($i = 0; $i <= 50000; $i++) { $num_tot = array_push($test2, $i); }
$s_test_end = FullMicroTime();
$f_test_begin = FullMicroTime();
for($i = 0; $i <= 50000; $i++) { $test[] = $i; $num_tot = count($test); }
$f_test_end = FullMicroTime();
----
Manual Page -- http://www.php.net/manual/en/function.array-push.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+39209
Delete -- http://master.php.net/manage/user-notes.php?action=delete+39209&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+39209&report=yes
Search -- http://master.php.net/manage/user-notes.php