3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php ini_set( 'MAX_EXEC_TIME', 120 ); $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/5aNS1 on line 26 There were 10 tests conducted, here's the totals<br /><br /> $i++ took -0.5360848903656 seconds and 0 bytes<br /> ++$i took 1.2227869033813 seconds and 0 bytes
Output for 7.0.14
Notice: Undefined index: time in /in/5aNS1 on line 26 There were 10 tests conducted, here's the totals<br /><br /> $i++ took 1.0614833831787 seconds and 0 bytes<br /> ++$i took 0.73080062866211 seconds and 0 bytes
Output for 7.0.10
Notice: Undefined index: time in /in/5aNS1 on line 26 There were 10 tests conducted, here's the totals<br /><br /> $i++ took 0.95521569252014 seconds and 0 bytes<br /> ++$i took 0.6720654964447 seconds and 0 bytes
Output for 7.0.9
Notice: Undefined index: time in /in/5aNS1 on line 26 There were 10 tests conducted, here's the totals<br /><br /> $i++ took 0.90372967720032 seconds and 0 bytes<br /> ++$i took 0.68338894844055 seconds and 0 bytes
Output for 7.0.8
Notice: Undefined index: time in /in/5aNS1 on line 26 There were 10 tests conducted, here's the totals<br /><br /> $i++ took 0.92919397354126 seconds and 0 bytes<br /> ++$i took 0.68685984611511 seconds and 0 bytes
Output for 7.0.7
Notice: Undefined index: time in /in/5aNS1 on line 26 There were 10 tests conducted, here's the totals<br /><br /> $i++ took 0.93744683265686 seconds and 0 bytes<br /> ++$i took 0.68531680107117 seconds and 0 bytes
Output for 7.0.6
Notice: Undefined index: time in /in/5aNS1 on line 26 There were 10 tests conducted, here's the totals<br /><br /> $i++ took 0.96785879135132 seconds and 0 bytes<br /> ++$i took 0.751145362854 seconds and 0 bytes
Output for 7.0.5
Notice: Undefined index: time in /in/5aNS1 on line 26 There were 10 tests conducted, here's the totals<br /><br /> $i++ took 0.91391491889954 seconds and 0 bytes<br /> ++$i took 0.70301461219788 seconds and 0 bytes
Output for 7.0.4
Notice: Undefined index: time in /in/5aNS1 on line 26 There were 10 tests conducted, here's the totals<br /><br /> $i++ took 0.98513793945312 seconds and 0 bytes<br /> ++$i took 0.77338910102844 seconds and 0 bytes
Output for 7.0.3
Notice: Undefined index: time in /in/5aNS1 on line 26 There were 10 tests conducted, here's the totals<br /><br /> $i++ took 0.9465663433075 seconds and 0 bytes<br /> ++$i took 0.66437101364136 seconds and 0 bytes
Output for 7.0.2
Notice: Undefined index: time in /in/5aNS1 on line 26 There were 10 tests conducted, here's the totals<br /><br /> $i++ took 0.89194512367249 seconds and 0 bytes<br /> ++$i took 0.63395619392395 seconds and 0 bytes
Output for 7.0.1
Notice: Undefined index: time in /in/5aNS1 on line 26 There were 10 tests conducted, here's the totals<br /><br /> $i++ took 0.91677761077881 seconds and 0 bytes<br /> ++$i took 0.67504501342773 seconds and 0 bytes
Output for 7.0.0
Notice: Undefined index: time in /in/5aNS1 on line 26 There were 10 tests conducted, here's the totals<br /><br /> $i++ took 0.92661237716675 seconds and 0 bytes<br /> ++$i took 0.7846622467041 seconds and 0 bytes
Output for 5.2.1 - 5.6.28, hhvm-3.10.0 - 3.12.0

Process exited with code 137.
Output for 5.0.0 - 5.2.0
Fatal error: Call to undefined function memory_get_usage() in /in/5aNS1 on line 11
Process exited with code 255.
Output for 4.4.5 - 4.4.9
Fatal error: Call to undefined function: memory_get_usage() in /in/5aNS1 on line 11
Process exited with code 255.
Output for 4.3.2 - 4.4.4
Fatal error: Call to undefined function: memory_get_usage() in /in/5aNS1 on line 11
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Call to undefined function: memory_get_usage() in /in/5aNS1 on line 11