3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $num_tests = 10; $startFirst = $startSecond = $endFirst = $endSecond = $startFirstMemory = $endFirstMemory = $startSecondMemory = $endSecondMemory = $someVal = 0; $times = array( '$i++' => array( 'time' => 0, 'memory' => 0 ), '++$i' => array( 'total' => 0, 'memory' => 0 ) ); for( $j = 0; $j < $num_tests; ++$j ) { for( $i = 0, $startFirstMemory = memory_get_usage( ), $startFirst = microtime( true ); $i < 10000000; $i++ ){ $someval = 2; } $endFirstMemory = memory_get_usage( ); $endFirst = microtime( true ); for( $i = 0, $startSecondMemory = memory_get_usage( ), $startSecond = microtime( true ); $i < 10000000; ++$i ){ $someval = 2; } $endSecondMemory = memory_get_usage( ); $endSecond = microtime( true ); $times[ '$i++' ][ $j ] = array( 'startTime' => $startFirst, 'endTime' => $endFirst, 'startMemory' => $startFirstMemory, 'endMemory' => $endFirstMemory ); $times[ '++$i' ][ $j ] = array( 'startTime' => $startSecond, 'endTime' => $endSecond, 'startMemory' => $startSecondMemory, 'endMemory' => $endSecondMemory ); } for( $i = 0; $i < $num_tests; ++$i ) { $times[ '$i++' ][ 'time' ] += ( $times[ '$i++' ][ $i ][ 'endTime' ] - $times[ '$i++' ][ $i ][ 'startTime' ] ); $times[ '++$i' ][ 'time' ] += ( $times[ '++$i' ][ $i ][ 'endTime' ] - $times[ '++$i' ][ $i ][ 'startTime' ] ); $times[ '$i++' ][ 'memory' ] += ( $times[ '$i++' ][ $i ][ 'endMemory' ] - $times[ '$i++' ][ $i ][ 'startMemory' ] ); $times[ '++$i' ][ 'memory' ] += ( $times[ '++$i' ][ $i ][ 'endMemory' ] - $times[ '++$i' ][ $i ][ 'startMemory' ] ); } echo 'There were ' . $num_tests . ' tests conducted, here\'s the totals<br /><br /> $i++ took ' . $times[ '$i++' ][ 'time' ] . ' seconds and ' . $times[ '$i++' ][ 'memory' ] . ' bytes<br /> ++$i took ' . $times[ '++$i' ][ 'time' ] . ' seconds and ' . $times[ '++$i' ][ 'memory' ] . ' bytes';
Output for 7.1.0
Notice: Undefined index: time in /in/UDD1l on line 23 There were 10 tests conducted, here's the totals<br /><br /> $i++ took 0.59178280830383 seconds and 0 bytes<br /> ++$i took 0.98357248306274 seconds and 0 bytes
Output for 7.0.14
Notice: Undefined index: time in /in/UDD1l on line 23 There were 10 tests conducted, here's the totals<br /><br /> $i++ took -0.51574277877808 seconds and 0 bytes<br /> ++$i took 1.1450448036194 seconds and 0 bytes
Output for 7.0.6
Notice: Undefined index: time in /in/UDD1l on line 23 There were 10 tests conducted, here's the totals<br /><br /> $i++ took 1.0836682319641 seconds and 0 bytes<br /> ++$i took 0.84347295761108 seconds and 0 bytes
Output for 7.0.5
Notice: Undefined index: time in /in/UDD1l on line 23 There were 10 tests conducted, here's the totals<br /><br /> $i++ took 1.0890181064606 seconds and 0 bytes<br /> ++$i took 0.83871936798096 seconds and 0 bytes
Output for 7.0.4
Notice: Undefined index: time in /in/UDD1l on line 23 There were 10 tests conducted, here's the totals<br /><br /> $i++ took 0.9936683177948 seconds and 0 bytes<br /> ++$i took 0.73339438438416 seconds and 0 bytes
Output for 7.0.3
Notice: Undefined index: time in /in/UDD1l on line 23 There were 10 tests conducted, here's the totals<br /><br /> $i++ took 1.0323731899261 seconds and 0 bytes<br /> ++$i took 0.76653647422791 seconds and 0 bytes
Output for 7.0.2
Notice: Undefined index: time in /in/UDD1l on line 23 There were 10 tests conducted, here's the totals<br /><br /> $i++ took 1.0607097148895 seconds and 0 bytes<br /> ++$i took 0.77825164794922 seconds and 0 bytes
Output for 7.0.1
Notice: Undefined index: time in /in/UDD1l on line 23 There were 10 tests conducted, here's the totals<br /><br /> $i++ took 1.1988162994385 seconds and 0 bytes<br /> ++$i took 0.91176295280457 seconds and 0 bytes
Output for 7.0.0
Notice: Undefined index: time in /in/UDD1l on line 23 There were 10 tests conducted, here's the totals<br /><br /> $i++ took 1.000837802887 seconds and 0 bytes<br /> ++$i took 0.73457145690918 seconds and 0 bytes
Output for 5.2.16 - 5.6.28, hhvm-3.10.0 - 3.12.0

Process exited with code 137.