3v4l.org

run code in 300+ PHP versions simultaneously
<?php $elements = array(); //// // An array of 10,000 elements with random string values //// for($i = 0; $i < 10000; $i++) { $elements[] = [(string)rand(10000000, 99999999)]; } $time_start = microtime(true); //// // for test //// $numb = count($elements); for($i = 0; $i < $numb; $i++) { $elements[$i][0] = 1; } $time_end = microtime(true); $for_time = $time_end - $time_start; $time_start = microtime(true); //// // for with count() inside loop test //// for($i = 0; $i < count($elements); $i++) { $elements[$i][0] = 1; } $time_end = microtime(true); $for_count_time = $time_end - $time_start; $time_start = microtime(true); //// // foreach test //// foreach($elements as &$element) { $element[0]= 1; } $time_end = microtime(true); $foreach_time = $time_end - $time_start; echo "For took: " . number_format($for_time * 1000, 3) . "ms\n"; echo "For with count() took: " . number_format($for_count_time * 1000, 3) . "ms\n"; echo "Foreach took: " . number_format($foreach_time * 1000, 3) . "ms\n";
Output for 7.2.4
For took: 0.857ms For with count() took: 0.387ms Foreach took: 1.093ms
Output for 7.2.3
For took: 1.214ms For with count() took: 0.722ms Foreach took: 1.462ms
Output for 7.2.2
For took: 6.085ms For with count() took: 0.366ms Foreach took: 0.965ms
Output for 7.2.1
For took: 1.094ms For with count() took: 0.941ms Foreach took: 1.108ms
Output for 7.2.0
For took: 0.819ms For with count() took: 0.417ms Foreach took: 0.964ms
Output for 7.1.16
For took: 0.881ms For with count() took: 0.654ms Foreach took: 0.951ms
Output for 7.1.15
For took: 0.894ms For with count() took: 0.667ms Foreach took: 1.123ms
Output for 7.1.14
For took: 1.094ms For with count() took: 1.066ms Foreach took: 1.333ms
Output for 7.1.13
For took: 0.843ms For with count() took: 0.563ms Foreach took: 0.938ms
Output for 7.1.12
For took: 0.792ms For with count() took: 0.561ms Foreach took: 0.910ms
Output for 7.1.11
For took: 0.781ms For with count() took: 0.645ms Foreach took: 0.906ms
Output for 7.1.10
For took: 0.782ms For with count() took: 0.543ms Foreach took: 0.970ms
Output for 7.1.9
For took: 0.782ms For with count() took: 0.590ms Foreach took: 0.949ms
Output for 7.1.8
For took: 0.783ms For with count() took: 0.624ms Foreach took: 0.934ms
Output for 7.1.7
For took: 0.797ms For with count() took: 0.572ms Foreach took: 0.908ms
Output for 7.1.6
For took: 0.844ms For with count() took: 0.519ms Foreach took: 0.895ms
Output for 7.1.5
For took: 0.859ms For with count() took: 0.574ms Foreach took: 0.902ms
Output for 7.1.4
For took: 0.792ms For with count() took: 0.621ms Foreach took: 0.894ms
Output for 7.1.3
For took: 0.763ms For with count() took: 0.638ms Foreach took: 0.920ms
Output for 7.1.2
For took: 0.774ms For with count() took: 0.698ms Foreach took: 0.911ms
Output for 7.1.1
For took: 0.792ms For with count() took: 0.499ms Foreach took: 0.891ms
Output for 7.1.0
For took: 0.807ms For with count() took: 0.512ms Foreach took: 0.922ms

preferences:
62.68 ms | 401 KiB | 27 Q