3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $iterations = 10000; $options = array('apple', 'banana', 'carrot' ,'date', 'endive'); $color = NULL; // Fill an array with random keys. This ensures // that (a) we use the same keys, and (b) // slowness in the randomizer doesn't impact the // loops (which can happen if entropy collection kicks in) $samples = array(); for ($i = 0; $i < $iterations; ++$i) { $samples[] = $options[rand(0, 4)]; } // Test a switch statement. $start_switch = microtime(TRUE); for ($i = 0; $i < $iterations; ++$i) { $option = $samples[$i]; switch ($option) { case 'apple': $color = 'red'; break; case 'banana': $color = 'yellow'; break; case 'carrot': $color = 'orange'; break; case 'date': $color = 'brown'; break; case 'endive': $color = 'green'; break; } } $end_switch = microtime(TRUE); $total_switch = $end_switch - $start_switch; printf("Switch:\t%0.6f sec to process %d" . PHP_EOL, $total_switch, $iterations); // Test an array lookup. $start_map = microtime(TRUE); for ($i = 0; $i < $iterations; ++$i) { $map = array( 'apple' => 'red', 'banana' => 'yellow', 'carrot' => 'orange', 'date' => 'brown', 'endive' => 'green' ); $color = $map[$samples[$i]]; } $end_map = microtime(TRUE); $total_map = $end_map - $start_map; printf("Map:\t%0.6f sec to process %d" . PHP_EOL, $total_map, $iterations);
Output for 7.1.0
Switch: 0.001135 sec to process 10000 Map: 0.000707 sec to process 10000
Output for 7.0.14
Switch: 0.000901 sec to process 10000 Map: 0.001864 sec to process 10000
Output for 7.0.6
Switch: 0.000853 sec to process 10000 Map: 0.002534 sec to process 10000
Output for 7.0.5
Switch: 0.000767 sec to process 10000 Map: 0.002324 sec to process 10000
Output for 7.0.4
Switch: 0.000869 sec to process 10000 Map: 0.001476 sec to process 10000
Output for 7.0.3
Switch: 0.000470 sec to process 10000 Map: 0.001423 sec to process 10000
Output for 7.0.2
Switch: 0.000779 sec to process 10000 Map: 0.002182 sec to process 10000
Output for 7.0.1
Switch: 0.000861 sec to process 10000 Map: 0.002423 sec to process 10000
Output for 7.0.0
Switch: 0.000731 sec to process 10000 Map: 0.002223 sec to process 10000
Output for 5.6.28
Switch: 0.002475 sec to process 10000 Map: 0.005289 sec to process 10000
Output for 5.6.21
Switch: 0.001881 sec to process 10000 Map: 0.004217 sec to process 10000
Output for 5.6.20
Switch: 0.001599 sec to process 10000 Map: 0.003526 sec to process 10000
Output for 5.6.19
Switch: 0.001311 sec to process 10000 Map: 0.002885 sec to process 10000
Output for 5.6.18
Switch: 0.001313 sec to process 10000 Map: 0.002908 sec to process 10000
Output for 5.6.17
Switch: 0.001307 sec to process 10000 Map: 0.002861 sec to process 10000
Output for 5.6.16
Switch: 0.001965 sec to process 10000 Map: 0.004430 sec to process 10000
Output for 5.6.15
Switch: 0.001606 sec to process 10000 Map: 0.003903 sec to process 10000
Output for 5.6.14
Switch: 0.001530 sec to process 10000 Map: 0.003463 sec to process 10000
Output for 5.6.13
Switch: 0.002653 sec to process 10000 Map: 0.006510 sec to process 10000
Output for 5.6.12
Switch: 0.002012 sec to process 10000 Map: 0.004566 sec to process 10000
Output for 5.6.11
Switch: 0.001956 sec to process 10000 Map: 0.004334 sec to process 10000
Output for 5.6.10
Switch: 0.002087 sec to process 10000 Map: 0.006211 sec to process 10000
Output for 5.6.9
Switch: 0.001819 sec to process 10000 Map: 0.003988 sec to process 10000
Output for 5.6.8
Switch: 0.001326 sec to process 10000 Map: 0.002955 sec to process 10000
Output for 5.5.35
Switch: 0.001994 sec to process 10000 Map: 0.004623 sec to process 10000
Output for 5.5.34
Switch: 0.001941 sec to process 10000 Map: 0.004219 sec to process 10000
Output for 5.5.33
Switch: 0.001687 sec to process 10000 Map: 0.003955 sec to process 10000
Output for 5.5.32
Switch: 0.001909 sec to process 10000 Map: 0.004048 sec to process 10000
Output for 5.5.31
Switch: 0.001331 sec to process 10000 Map: 0.003018 sec to process 10000
Output for 5.5.30
Switch: 0.001281 sec to process 10000 Map: 0.003067 sec to process 10000
Output for 5.5.29
Switch: 0.001420 sec to process 10000 Map: 0.003318 sec to process 10000
Output for 5.5.28
Switch: 0.002099 sec to process 10000 Map: 0.004711 sec to process 10000
Output for 5.5.27
Switch: 0.001408 sec to process 10000 Map: 0.003281 sec to process 10000
Output for 5.5.26
Switch: 0.001554 sec to process 10000 Map: 0.003646 sec to process 10000
Output for 5.5.25
Switch: 0.002082 sec to process 10000 Map: 0.004639 sec to process 10000
Output for 5.5.24
Switch: 0.001906 sec to process 10000 Map: 0.004360 sec to process 10000
Output for 5.4.45
Switch: 0.001890 sec to process 10000 Map: 0.004743 sec to process 10000
Output for 5.4.44
Switch: 0.002685 sec to process 10000 Map: 0.009146 sec to process 10000
Output for 5.4.43
Switch: 0.002245 sec to process 10000 Map: 0.005570 sec to process 10000
Output for 5.4.42
Switch: 0.002247 sec to process 10000 Map: 0.005214 sec to process 10000
Output for 5.4.41
Switch: 0.002861 sec to process 10000 Map: 0.007507 sec to process 10000
Output for 5.4.40
Switch: 0.001909 sec to process 10000 Map: 0.004514 sec to process 10000
Output for 5.4.39
Switch: 0.001918 sec to process 10000 Map: 0.004510 sec to process 10000
Output for 5.4.38
Switch: 0.002869 sec to process 10000 Map: 0.008160 sec to process 10000
Output for 5.4.37
Switch: 0.001901 sec to process 10000 Map: 0.004500 sec to process 10000
Output for 5.4.36
Switch: 0.001890 sec to process 10000 Map: 0.004447 sec to process 10000
Output for 5.4.35
Switch: 0.002464 sec to process 10000 Map: 0.004973 sec to process 10000
Output for 5.4.34
Switch: 0.001413 sec to process 10000 Map: 0.003677 sec to process 10000
Output for 5.4.32
Switch: 0.001440 sec to process 10000 Map: 0.003535 sec to process 10000
Output for 5.4.31
Switch: 0.001424 sec to process 10000 Map: 0.003493 sec to process 10000
Output for 5.4.30
Switch: 0.001542 sec to process 10000 Map: 0.003549 sec to process 10000
Output for 5.4.29
Switch: 0.001533 sec to process 10000 Map: 0.003454 sec to process 10000
Output for 5.4.28
Switch: 0.001663 sec to process 10000 Map: 0.003700 sec to process 10000
Output for 5.4.27
Switch: 0.002156 sec to process 10000 Map: 0.003456 sec to process 10000
Output for 5.4.26
Switch: 0.001393 sec to process 10000 Map: 0.004110 sec to process 10000
Output for 5.4.25
Switch: 0.001422 sec to process 10000 Map: 0.003360 sec to process 10000
Output for 5.4.24
Switch: 0.001557 sec to process 10000 Map: 0.003581 sec to process 10000
Output for 5.4.23
Switch: 0.001434 sec to process 10000 Map: 0.003405 sec to process 10000
Output for 5.4.22
Switch: 0.002086 sec to process 10000 Map: 0.003655 sec to process 10000
Output for 5.4.21
Switch: 0.002043 sec to process 10000 Map: 0.003943 sec to process 10000
Output for 5.4.20
Switch: 0.001463 sec to process 10000 Map: 0.007600 sec to process 10000
Output for 5.4.19
Switch: 0.003428 sec to process 10000 Map: 0.008941 sec to process 10000
Output for 5.4.18
Switch: 0.001810 sec to process 10000 Map: 0.003881 sec to process 10000
Output for 5.4.17
Switch: 0.001421 sec to process 10000 Map: 0.003555 sec to process 10000
Output for 5.4.16
Switch: 0.001438 sec to process 10000 Map: 0.003485 sec to process 10000
Output for 5.4.15
Switch: 0.001527 sec to process 10000 Map: 0.003294 sec to process 10000
Output for 5.4.14
Switch: 0.003148 sec to process 10000 Map: 0.005259 sec to process 10000
Output for 5.4.13
Switch: 0.002156 sec to process 10000 Map: 0.005355 sec to process 10000
Output for 5.4.12
Switch: 0.001675 sec to process 10000 Map: 0.003773 sec to process 10000
Output for 5.4.11
Switch: 0.001511 sec to process 10000 Map: 0.003583 sec to process 10000
Output for 5.4.10
Switch: 0.001924 sec to process 10000 Map: 0.003738 sec to process 10000
Output for 5.4.9
Switch: 0.001754 sec to process 10000 Map: 0.003817 sec to process 10000
Output for 5.4.8
Switch: 0.001425 sec to process 10000 Map: 0.003668 sec to process 10000
Output for 5.4.7
Switch: 0.001634 sec to process 10000 Map: 0.003762 sec to process 10000
Output for 5.4.6
Switch: 0.001460 sec to process 10000 Map: 0.003451 sec to process 10000
Output for 5.4.5
Switch: 0.001553 sec to process 10000 Map: 0.004898 sec to process 10000
Output for 5.4.4
Switch: 0.001941 sec to process 10000 Map: 0.003858 sec to process 10000
Output for 5.4.3
Switch: 0.001467 sec to process 10000 Map: 0.004050 sec to process 10000
Output for 5.4.2
Switch: 0.001653 sec to process 10000 Map: 0.003646 sec to process 10000
Output for 5.4.1
Switch: 0.001577 sec to process 10000 Map: 0.003858 sec to process 10000
Output for 5.4.0
Switch: 0.001542 sec to process 10000 Map: 0.004129 sec to process 10000
Output for 5.3.29
Switch: 0.002025 sec to process 10000 Map: 0.004611 sec to process 10000
Output for 5.3.28
Switch: 0.002329 sec to process 10000 Map: 0.004859 sec to process 10000
Output for 5.3.27
Switch: 0.002061 sec to process 10000 Map: 0.004618 sec to process 10000
Output for 5.3.26
Switch: 0.001739 sec to process 10000 Map: 0.006599 sec to process 10000
Output for 5.3.25
Switch: 0.001790 sec to process 10000 Map: 0.004690 sec to process 10000
Output for 5.3.24
Switch: 0.001886 sec to process 10000 Map: 0.004701 sec to process 10000
Output for 5.3.23
Switch: 0.001862 sec to process 10000 Map: 0.004799 sec to process 10000
Output for 5.3.22
Switch: 0.001824 sec to process 10000 Map: 0.005279 sec to process 10000
Output for 5.3.21
Switch: 0.002070 sec to process 10000 Map: 0.005406 sec to process 10000
Output for 5.3.20
Switch: 0.001906 sec to process 10000 Map: 0.005087 sec to process 10000
Output for 5.3.19
Switch: 0.001898 sec to process 10000 Map: 0.005381 sec to process 10000
Output for 5.3.18
Switch: 0.001915 sec to process 10000 Map: 0.005292 sec to process 10000
Output for 5.3.17
Switch: 0.002231 sec to process 10000 Map: 0.005879 sec to process 10000
Output for 5.3.16
Switch: 0.001887 sec to process 10000 Map: 0.005359 sec to process 10000
Output for 5.3.15
Switch: 0.001856 sec to process 10000 Map: 0.005035 sec to process 10000
Output for 5.3.14
Switch: 0.001869 sec to process 10000 Map: 0.005415 sec to process 10000
Output for 5.3.13
Switch: 0.001938 sec to process 10000 Map: 0.005065 sec to process 10000
Output for 5.3.12
Switch: 0.001892 sec to process 10000 Map: 0.005014 sec to process 10000
Output for 5.3.11
Switch: 0.001825 sec to process 10000 Map: 0.004904 sec to process 10000
Output for 5.3.10
Switch: 0.002238 sec to process 10000 Map: 0.005118 sec to process 10000
Output for 5.3.9
Switch: 0.001759 sec to process 10000 Map: 0.004877 sec to process 10000
Output for 5.3.8
Switch: 0.001795 sec to process 10000 Map: 0.006982 sec to process 10000
Output for 5.3.7
Switch: 0.001765 sec to process 10000 Map: 0.004852 sec to process 10000
Output for 5.3.6
Switch: 0.004642 sec to process 10000 Map: 0.009869 sec to process 10000
Output for 5.3.5
Switch: 0.001816 sec to process 10000 Map: 0.004839 sec to process 10000
Output for 5.3.4
Switch: 0.001881 sec to process 10000 Map: 0.005279 sec to process 10000
Output for 5.3.3
Switch: 0.001866 sec to process 10000 Map: 0.004977 sec to process 10000
Output for 5.3.2
Switch: 0.001788 sec to process 10000 Map: 0.004776 sec to process 10000
Output for 5.3.1
Switch: 0.001789 sec to process 10000 Map: 0.005068 sec to process 10000
Output for 5.3.0
Switch: 0.002329 sec to process 10000 Map: 0.005231 sec to process 10000
Output for 5.2.17
Switch: 0.002443 sec to process 10000 Map: 0.005452 sec to process 10000
Output for 5.2.16
Switch: 0.002491 sec to process 10000 Map: 0.005607 sec to process 10000
Output for 5.2.15
Switch: 0.002404 sec to process 10000 Map: 0.005452 sec to process 10000
Output for 5.2.14
Switch: 0.005044 sec to process 10000 Map: 0.006681 sec to process 10000
Output for 5.2.13
Switch: 0.002394 sec to process 10000 Map: 0.005333 sec to process 10000
Output for 5.2.12
Switch: 0.005741 sec to process 10000 Map: 0.006070 sec to process 10000
Output for 5.2.11
Switch: 0.002617 sec to process 10000 Map: 0.006061 sec to process 10000
Output for 5.2.10
Switch: 0.002530 sec to process 10000 Map: 0.005469 sec to process 10000
Output for 5.2.9
Switch: 0.002797 sec to process 10000 Map: 0.005692 sec to process 10000
Output for 5.2.8
Switch: 0.002680 sec to process 10000 Map: 0.005607 sec to process 10000
Output for 5.2.7
Switch: 0.002554 sec to process 10000 Map: 0.005765 sec to process 10000
Output for 5.2.6
Switch: 0.002670 sec to process 10000 Map: 0.005679 sec to process 10000
Output for 5.2.5
Switch: 0.002476 sec to process 10000 Map: 0.005984 sec to process 10000
Output for 5.2.4
Switch: 0.002636 sec to process 10000 Map: 0.005807 sec to process 10000
Output for 5.2.3
Switch: 0.002954 sec to process 10000 Map: 0.007302 sec to process 10000
Output for 5.2.2
Switch: 0.002400 sec to process 10000 Map: 0.005871 sec to process 10000
Output for 5.2.1
Switch: 0.002682 sec to process 10000 Map: 0.006062 sec to process 10000
Output for 5.2.0
Switch: 0.002868 sec to process 10000 Map: 0.005603 sec to process 10000
Output for 5.1.6
Switch: 0.002991 sec to process 10000 Map: 0.005408 sec to process 10000
Output for 5.1.5
Switch: 0.003365 sec to process 10000 Map: 0.005645 sec to process 10000
Output for 5.1.4
Switch: 0.002984 sec to process 10000 Map: 0.005464 sec to process 10000
Output for 5.1.3
Switch: 0.003464 sec to process 10000 Map: 0.005639 sec to process 10000
Output for 5.1.2
Switch: 0.002965 sec to process 10000 Map: 0.005811 sec to process 10000
Output for 5.1.1
Switch: 0.004923 sec to process 10000 Map: 0.009688 sec to process 10000
Output for 5.1.0
Switch: 0.002925 sec to process 10000 Map: 0.005847 sec to process 10000
Output for 5.0.5
Switch: 0.006829 sec to process 10000 Map: 0.009109 sec to process 10000
Output for 5.0.4
Switch: 0.007028 sec to process 10000 Map: 0.009302 sec to process 10000
Output for 5.0.3
Switch: 0.006187 sec to process 10000 Map: 0.009781 sec to process 10000
Output for 5.0.2
Switch: 0.007059 sec to process 10000 Map: 0.009276 sec to process 10000
Output for 5.0.1
Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/Ce3l0 on line 41 Switch: 0.006775 sec to process 10000PHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/Ce3l0 on line 59 Map: 0.009434 sec to process 10000PHP_EOL
Output for 5.0.0
Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/Ce3l0 on line 41 Switch: 0.007464 sec to process 10000PHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/Ce3l0 on line 59 Map: 0.009332 sec to process 10000PHP_EOL
Output for 4.4.9
Switch: 0.006572 sec to process 10000 Map: 0.009012 sec to process 10000
Output for 4.4.8
Switch: 0.006882 sec to process 10000 Map: 0.009178 sec to process 10000
Output for 4.4.7
Switch: 0.006831 sec to process 10000 Map: 0.008912 sec to process 10000
Output for 4.4.6
Switch: 0.012318 sec to process 10000 Map: 0.011716 sec to process 10000
Output for 4.4.5
Switch: 0.006623 sec to process 10000 Map: 0.009563 sec to process 10000
Output for 4.4.4
Switch: 0.010724 sec to process 10000 Map: 0.015957 sec to process 10000
Output for 4.4.3
Switch: 0.006399 sec to process 10000 Map: 0.009247 sec to process 10000
Output for 4.4.2
Switch: 0.006543 sec to process 10000 Map: 0.009101 sec to process 10000
Output for 4.4.1
Switch: 0.006655 sec to process 10000 Map: 0.012250 sec to process 10000
Output for 4.4.0
Switch: 0.006809 sec to process 10000 Map: 0.009491 sec to process 10000
Output for 4.3.11
Switch: 0.006967 sec to process 10000 Map: 0.008995 sec to process 10000
Output for 4.3.10
Switch: 0.006431 sec to process 10000 Map: 0.008460 sec to process 10000
Output for 4.3.9
Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/Ce3l0 on line 41 Switch: 0.006777 sec to process 10000PHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/Ce3l0 on line 59 Map: 0.008640 sec to process 10000PHP_EOL
Output for 4.3.8
Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/Ce3l0 on line 41 Switch: 0.006924 sec to process 10000PHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/Ce3l0 on line 59 Map: 0.008439 sec to process 10000PHP_EOL
Output for 4.3.7
Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/Ce3l0 on line 41 Switch: 0.006795 sec to process 10000PHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/Ce3l0 on line 59 Map: 0.010468 sec to process 10000PHP_EOL
Output for 4.3.6
Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/Ce3l0 on line 41 Switch: 0.006950 sec to process 10000PHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/Ce3l0 on line 59 Map: 0.009401 sec to process 10000PHP_EOL
Output for 4.3.5
Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/Ce3l0 on line 41 Switch: 0.006782 sec to process 10000PHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/Ce3l0 on line 59 Map: 0.009508 sec to process 10000PHP_EOL
Output for 4.3.4
Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/Ce3l0 on line 41 Switch: 0.006873 sec to process 10000PHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/Ce3l0 on line 59 Map: 0.008999 sec to process 10000PHP_EOL
Output for 4.3.3
Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/Ce3l0 on line 41 Switch: 0.007170 sec to process 10000PHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/Ce3l0 on line 59 Map: 0.009023 sec to process 10000PHP_EOL
Output for 4.3.2
Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/Ce3l0 on line 41 Switch: 0.006393 sec to process 10000PHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/Ce3l0 on line 59 Map: 0.008312 sec to process 10000PHP_EOL
Output for 4.3.1
Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/Ce3l0 on line 41 Switch: 0.006873 sec to process 10000PHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/Ce3l0 on line 59 Map: 0.008132 sec to process 10000PHP_EOL
Output for 4.3.0
Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/Ce3l0 on line 41 Switch: 0.012720 sec to process 10000PHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/Ce3l0 on line 59 Map: 0.012237 sec to process 10000PHP_EOL