3v4l.org

run code in 300+ PHP versions simultaneously
<?php namespace Benchmark; final class Measure { const MEMORY_VALUE = 0; const BENCHMARK_VALUE = 1; const BENCHMARK_AVERAGE = 2; const BENCHMARK_COUNT = 3; private $max, $memory, $trace; public function memoryTick() { $this->memory = memory_get_usage() - $this->memory; $this->max = $this->memory>$this->max?$this->memory:$this->max; $this->memory = memory_get_usage(); } public function profileTick() { $memory = memory_get_usage(); $this->trace[] = $memory-$this->memory; $this->memory = memory_get_usage(); } /** * * @param callable $function A function to be measured * @param array $args Parameters to be passed for measured function * @return array Result contains profile data per each line */ public function profileMemory(callable $function, array $args=array()) { declare(ticks=1); $this->memory = memory_get_usage(); $this->max = 0; $this->trace = array(); register_tick_function('call_user_func', array($this, 'profileTick')); $this->measureFunction($function, $args, 1); unregister_tick_function('call_user_func'); return $this->trace; } /** * * @param callable $function A function to be measured * @param array $args Parameters to be passed for measured function * @return array Result currently contains one value: used memory space */ public function benchmarkMemory(callable $function, array $args=array()) { declare(ticks=1); $this->memory = memory_get_usage(); $this->max = 0; register_tick_function('call_user_func', array($this, 'memoryTick')); $this->measureFunction($function, $args, 1); unregister_tick_function('call_user_func'); return array( self::MEMORY_VALUE => $this->max ); } /** * * @param callable $function A function to be measured * @param array $args Parameters to be passed for measured function * @param int $count Count of measurements * @return array Result currently contains: total time, average time and measurements count * @throws \InvalidArgumentException If measurements count is invalid */ public function benchmarkTime(callable $function, array $args=array(), $count=1) { return $this->benchmarkCustom('microtime', $function, array(1), $args, $count); } /** * * @param callable $benchmark Function which will do measurements * @param callable $function A function to be measured * @param array $benchmarkArgs Parameters to be passed for measurement function * @param array $functionArgs Parameters to be passed for measured function * @param int $count Count of measurements * @return array Result currently contains: total value, average value and measurements count * @throws \InvalidArgumentException If measurements count is invalid * @throws \LogicException If measurement function did not returned numeric value */ public function benchmarkCustom(callable $benchmark, callable $function, array $benchmarkArgs=array(), array $functionArgs=array(), $count=1) { if(!is_int($count) || $count <=0) { throw new \InvalidArgumentException('Count of measure times must be positive integer'); } $init = call_user_func_array($benchmark, $benchmarkArgs); if(!is_numeric($init)) { throw new \LogicException('Benchmark function must return valid numeric value'); } $this->measureFunction($function, $functionArgs, $count); $end = call_user_func_array($benchmark, $benchmarkArgs); return array( self::BENCHMARK_VALUE => $end - $init, self::BENCHMARK_AVERAGE => ($end - $init) / $count, self::BENCHMARK_COUNT => $count ); } private function measureFunction($function, $args, $count) { for($i=0; $i<$count; $i++) { call_user_func_array($function, $args); } } }

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
8.0.110.0000.00816.71
8.0.100.0000.00716.71
8.0.90.0050.00316.62
8.0.80.0070.00716.83
8.0.70.0000.00716.88
8.0.60.0040.00416.73
8.0.50.0030.00616.76
8.0.30.0090.01416.86
8.0.20.0140.00817.40
8.0.10.0030.00516.90
8.0.00.0090.01216.62
7.4.240.0020.00516.55
7.4.230.0000.00716.60
7.4.220.0110.00416.35
7.4.210.0110.00416.59
7.4.200.0070.00016.45
7.4.190.0000.00716.56
7.4.160.0120.00316.30
7.4.150.0140.00317.40
7.4.140.0120.00517.86
7.4.130.0130.00816.52
7.4.120.0120.00716.41
7.4.110.0110.00716.43
7.4.100.0090.00916.21
7.4.90.0070.01116.42
7.4.80.0080.01219.39
7.4.70.0160.00016.30
7.4.60.0030.01416.53
7.4.50.0050.00016.15
7.4.40.0070.01122.77
7.4.30.0120.00416.12
7.4.00.0120.00314.77
7.3.300.0030.00316.27
7.3.290.0060.00816.15
7.3.280.0080.01116.18
7.3.270.0100.00717.40
7.3.260.0120.00616.14
7.3.250.0140.01016.26
7.3.240.0100.01416.48
7.3.230.0090.00916.43
7.3.210.0090.01416.39
7.3.200.0060.01119.39
7.3.190.0150.00616.32
7.3.180.0030.01216.34
7.3.170.0150.00616.27
7.3.160.0050.01416.36
7.3.120.0130.00314.70
7.3.110.0030.01014.74
7.3.100.0060.00314.89
7.3.90.0030.00714.77
7.3.80.0060.00614.86
7.3.70.0080.00314.53
7.3.60.0040.00414.70
7.3.50.0040.00814.49
7.3.40.0060.00614.77
7.3.30.0070.00414.71
7.3.20.0060.00616.57
7.3.10.0000.01316.31
7.3.00.0060.00316.31
7.2.330.0110.00816.56
7.2.320.0120.00616.55
7.2.310.0070.01016.36
7.2.300.0090.00916.45
7.2.290.0000.01616.58
7.2.240.0030.01514.59
7.2.230.0000.00814.95
7.2.220.0030.00714.84
7.2.210.0040.00714.45
7.2.200.0080.00414.93
7.2.190.0070.00714.88
7.2.180.0100.00714.86
7.2.170.0030.01214.59
7.2.160.0050.00814.70
7.2.150.0000.01516.42
7.2.140.0030.01016.34
7.2.130.0030.01216.88
7.2.120.0090.00616.69
7.2.110.0130.00316.76
7.2.100.0030.01016.54
7.2.90.0100.00316.67
7.2.80.0040.00716.80
7.2.70.0040.00716.70
7.2.60.0070.00316.96
7.2.50.0100.00316.68
7.2.40.0000.01016.76
7.2.30.0080.00316.76
7.2.20.0090.00916.51
7.2.10.0090.00616.45
7.2.00.0080.00818.09
7.1.330.0070.00715.54
7.1.320.0060.00615.59
7.1.310.0030.01015.71
7.1.300.0030.01415.57
7.1.290.0000.01515.49
7.1.280.0090.00315.72
7.1.270.0090.00315.63
7.1.260.0040.01115.43
7.1.250.0030.01015.73
7.1.100.0000.01117.77
7.1.70.0030.00716.99
7.1.60.0000.01017.30
7.1.50.0000.01116.83
7.1.40.0060.00616.50
7.1.30.0070.01116.75
7.1.20.0060.00916.79
7.1.10.0000.00716.61
7.1.00.0050.00316.54
7.0.200.0000.00716.66
7.0.190.0040.00416.63
7.0.180.0000.00815.99
7.0.170.0000.00816.17
7.0.160.0040.00416.20
7.0.150.0030.00716.02
7.0.140.0000.00716.01
7.0.130.0090.00016.52
7.0.120.0070.00416.37
7.0.110.0000.00916.14
7.0.100.0080.00016.30
7.0.90.0090.00016.14
7.0.80.0000.01116.25
7.0.70.0000.00715.95
7.0.60.0040.00815.87
7.0.50.0040.00416.14
7.0.40.0030.00915.18
7.0.30.0000.01115.18
7.0.20.0040.00415.18
7.0.10.0000.00915.18
7.0.00.0000.00815.18
5.6.300.0110.03220.60
5.6.290.0000.04520.79
5.6.280.0070.04021.02
5.6.270.0030.04520.95
5.6.260.0030.04120.94
5.6.250.0000.04620.81
5.6.240.0030.05420.90
5.6.230.0030.05220.84
5.6.220.0000.04220.86
5.6.210.0060.04121.00
5.6.200.0070.04321.07
5.6.190.0000.04721.06
5.6.180.0100.04421.09
5.6.170.0130.03521.07
5.6.160.0000.04520.89
5.6.150.0070.04721.02
5.6.140.0060.03821.02
5.6.130.0000.04620.83
5.6.120.0030.04420.95
5.6.110.0130.05020.86
5.6.100.0070.08421.04
5.6.90.0060.04820.88
5.6.80.0030.05820.46
5.6.70.0030.08220.17
5.6.60.0070.04220.14
5.6.50.0070.03720.26
5.6.40.0060.03520.13
5.6.30.0030.03920.32
5.6.20.0030.04020.09
5.6.10.0070.03720.11
5.6.00.0060.03920.21
5.5.380.0000.04017.64
5.5.370.0030.03817.57
5.5.360.0070.06017.62
5.5.350.0030.04017.62
5.5.340.0200.03917.73
5.5.330.0000.04817.85
5.5.320.0030.04618.02
5.5.310.0000.04318.18
5.5.300.0060.03517.74
5.5.290.0030.04517.71
5.5.280.0060.04117.71
5.5.270.0000.05018.09
5.5.260.0030.04817.85
5.5.250.0030.03817.86
5.5.240.0030.04517.43
5.5.230.0030.04617.45
5.5.220.0030.03917.47
5.5.210.0030.03717.42
5.5.200.0070.03217.51
5.5.190.0030.03817.38
5.5.180.0000.05517.50
5.5.160.0000.06617.45
5.5.150.0060.03817.09
5.5.140.0030.04417.54
5.5.130.0000.04217.05
5.5.120.0000.04317.07
5.5.110.0030.04217.05
5.5.100.0030.03817.26
5.5.90.0000.04616.96
5.5.80.0030.03617.34
5.5.70.0030.04417.29
5.5.60.0000.04517.34
5.5.50.0060.03817.09
5.5.40.0030.04017.25
5.5.30.0060.03917.30
5.5.20.0070.05217.32
5.5.10.0070.03517.34
5.5.00.0000.04517.07
5.4.450.0070.03819.31
5.4.440.0030.04119.53
5.4.430.0090.03519.55
5.4.420.0000.04819.30
5.4.410.0060.03519.14
5.4.400.0030.03819.07
5.4.390.0000.04318.98
5.4.380.0030.03919.08
5.4.370.0030.04319.19
5.4.360.0040.03719.14
5.4.350.0100.03818.98
5.4.340.0060.03619.23
5.4.320.0070.04318.98
5.4.310.0000.04318.99
5.4.300.0090.03319.11
5.4.290.0090.03218.90
5.4.280.0070.03619.11
5.4.270.0060.03419.16
5.4.260.0090.03118.95
5.4.250.0030.04219.08
5.4.240.0030.04119.07
5.4.230.0030.04419.14
5.4.220.0030.04419.10
5.4.210.0030.04619.21
5.4.200.0030.04119.13
5.4.190.0100.03619.21
5.4.180.0070.04619.10
5.4.170.0100.04818.96
5.4.160.0070.04019.18
5.4.150.0060.04819.09
5.4.140.0000.04816.57
5.4.130.0200.04716.46
5.4.120.0060.03616.59
5.4.110.0030.04016.35
5.4.100.0100.03816.71
5.4.90.0120.04416.71
5.4.80.0110.04216.74
5.4.70.0040.04316.79
5.4.60.0130.04116.78
5.4.50.0120.03916.70
5.4.40.0130.04216.44
5.4.30.0070.04016.63
5.4.20.0220.03016.71
5.4.10.0160.03316.52
5.4.00.0090.04416.14
5.3.290.0000.04415.18
5.3.280.0040.03915.18
5.3.270.0030.04215.18
5.3.260.0000.04215.18
5.3.250.0030.04215.18
5.3.240.0070.04215.18
5.3.230.0030.03915.18
5.3.220.0070.03915.18
5.3.210.0060.04115.18
5.3.200.0080.03815.18
5.3.190.0070.04415.18
5.3.180.0130.03515.18
5.3.170.0140.04415.18
5.3.160.0070.04115.18
5.3.150.0000.04715.18
5.3.140.0090.03715.18
5.3.130.0160.03515.18
5.3.120.0060.04415.18
5.3.110.0120.03715.18
5.3.100.0120.03415.18
5.3.90.0140.03815.18
5.3.80.0120.03315.18
5.3.70.0090.03415.18
5.3.60.0100.03515.18
5.3.50.0150.03315.18
5.3.40.0130.03615.18
5.3.30.0160.03115.18
5.3.20.0140.03215.18
5.3.10.0070.03615.18
5.3.00.0000.04115.18
5.2.170.0030.03615.18
5.2.160.0090.02915.18
5.2.150.0210.02815.18
5.2.140.0040.03615.18
5.2.130.0040.03215.18
5.2.120.0130.03015.18
5.2.110.0040.03315.18
5.2.100.0060.02515.18
5.2.90.0000.03415.18
5.2.80.0060.03015.18
5.2.70.0000.03115.18
5.2.60.0070.05315.18
5.2.50.0100.02215.18
5.2.40.0000.03215.18
5.2.30.0030.03515.18
5.2.20.0040.03915.18
5.2.10.0030.02715.18
5.2.00.0030.03315.18
5.1.60.0040.02615.18
5.1.50.0070.02115.18
5.1.40.0030.02615.18
5.1.30.0030.02615.18
5.1.20.0000.03115.18
5.1.10.0030.02815.18
5.1.00.0060.02215.18
5.0.50.0040.02115.18
5.0.40.0040.01815.18
5.0.30.0070.02615.18
5.0.20.0000.02115.18
5.0.10.0030.02015.18
5.0.00.0000.03215.18
4.4.90.0030.02015.18
4.4.80.0030.02015.18
4.4.70.0030.01615.18
4.4.60.0000.01915.18
4.4.50.0000.01915.18
4.4.40.0130.02815.18
4.4.30.0000.01915.18
4.4.20.0000.01715.18
4.4.10.0000.01615.18
4.4.00.0030.02315.18
4.3.110.0100.01415.18
4.3.100.0000.01615.18
4.3.90.0030.01715.18
4.3.80.0000.02615.18
4.3.70.0000.01615.18
4.3.60.0000.02115.18
4.3.50.0060.02215.18
4.3.40.0000.02615.18
4.3.30.0000.02015.18
4.3.20.0040.01415.18
4.3.10.0090.00915.18
4.3.00.0030.01615.18

preferences:
39.88 ms | 400 KiB | 5 Q