Debian Codegraph @

benchmark/php/array-get.php

raw
1 <?php
2 ini_set('memory_limit', '256M');
3
4 $COUNT = 1e6;
5 $a = array();
6
7 for ($i = 0; $i < $COUNT; $i++) {
8 $a[$i] = $i;
9 }
10
11 $start = microtime(true);
12 for ($i = 0; $i < $COUNT; $i++) {
13 if ($a[$i] !== $i) {
14 throw new Exception();
15 }
16 }
17
18 $ms = (microtime(true) - $start) * 1000;
19 $mhz = ((($COUNT / ($ms / 1000)) / 1e6));
20 $million = $COUNT / 1e6;
21
22 echo sprintf("%.2f Mhz (%d million in %d ms)\n", $mhz, $million, $ms);