Created
July 7, 2015 07:52
-
-
Save keopx/86ed1a28bcaa6e6bd1bf to your computer and use it in GitHub Desktop.
Speed Test: array_push vs $array[]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$time_start = microtime(true); | |
$myArray = array(); | |
for ($i = 0; $i < 100000; ++$i) { | |
$myArray[] = $i; | |
$myArray[] = 'test a string'; | |
} | |
$time_end = microtime(true); | |
printf("Took %f seconds for array[]\n", $time_end - $time_start); | |
$time_start = microtime(true); | |
$myArray = array(); | |
for ($i = 0; $i < 100000; ++$i) { | |
array_push($myArray, $i); | |
array_push($myArray, 'test a string'); | |
} | |
$time_end = microtime(true); | |
printf("Took %f seconds for array_push\n", $time_end - $time_start); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment