note 39209 deleted from function.array-push by peehaa
| From: | peehaa@php.net | Date: | Tue, 21 Mar 2017 08:39:18 +0000 |
| Subject: | note 39209 deleted from function.array-push by peehaa | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-208922@lists.php.net to get a copy of this message | ||
Note Submitter: skiflyer
----
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();