Created
December 17, 2018 11:58
-
-
Save Raffaello/251c0d2c0fb3b4dffe82dcc96831213e to your computer and use it in GitHub Desktop.
Benchmarks
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 | |
$numbers = \range(0, 100000); | |
$result = []; | |
$start = \microtime(true); | |
foreach ($numbers as $number) { | |
$result[] = $number * 10; | |
} | |
$end = \microtime(true); | |
echo 'total time foreach: ' . ($end-$start); | |
echo "\n"; | |
$start = \microtime(true); | |
$result = \array_map(function($n) { return $n * 10; }, $numbers); | |
$end = \microtime(true); | |
echo 'total time map: ' . ($end-$start); | |
/* | |
* Results: PHP5.6 (related to V1 environment) | |
+ total time foreach: 0.26890397071838 | |
- total time map: 1.4822571277618 | |
Results: PHP7.2 | |
+ total time foreach: 0.012457847595215 | |
- total time map: 0.098356962203979 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment