3v4l.org

run code in 300+ PHP versions simultaneously
<?php error_reporting(-1); ini_set('display_errors', '1'); ini_set('display_startup_errors', '1'); mb_internal_encoding('UTF-8'); mb_http_output('UTF-8'); gc_enable(); class Ubench { protected $start_time; protected $end_time; protected $memory_usage; /** * Sets start microtime * * @return void */ public function start() { $this->start_time = microtime(true); } /** * Sets end microtime * * @return void */ public function end() { $this->end_time = microtime(true); $this->memory_usage = memory_get_usage(true); } /** * Returns the elapsed time, readable or not * * @param boolean $readable Whether the result must be human readable * @param string $format The format to display (printf format) * @return string|float */ public function getTime($raw = false, $format = null) { $elapsed = $this->end_time - $this->start_time; return $raw ? $elapsed : self::readableElapsedTime($elapsed, $format); } /** * Returns the memory usage at the end checkpoint * * @param boolean $readable Whether the result must be human readable * @param string $format The format to display (printf format) * @return string|float */ public function getMemoryUsage($raw = false, $format = null) { return $raw ? $this->memory_usage : self::readableSize($this->memory_usage, $format); } /** * Returns the memory peak, readable or not * * @param boolean $readable Whether the result must be human readable * @param string $format The format to display (printf format) * @return string|float */ public function getMemoryPeak($raw = false, $format = null) { $memory = memory_get_peak_usage(true); return $raw ? $memory : self::readableSize($memory, $format); } /** * Wraps a callable with start() and end() calls * * Additional arguments passed to this method will be passed to * the callable. * * @param callable $callable * @return mixed */ public function run(callable $callable) { $arguments = func_get_args(); array_shift($arguments); $this->start(); $result = call_user_func_array($callable, $arguments); $this->end(); return $result; } /** * Returns a human readable memory size * * @param int $size * @param string $format The format to display (printf format) * @param int $round * @return string */ public static function readableSize($size, $format = null, $round = 3) { $mod = 1024; if (is_null($format)) { $format = '%.2f%s'; } $units = explode(' ','B Kb Mb Gb Tb'); for ($i = 0; $size > $mod; $i++) { $size /= $mod; } if (0 === $i) { $format = preg_replace('/(%.[\d]+f)/', '%d', $format); } return sprintf($format, round($size, $round), $units[$i]); } /** * Returns a human readable elapsed time * * @param float $microtime * @param string $format The format to display (printf format) * @return string */ public static function readableElapsedTime($microtime, $format = null, $round = 3) { if (is_null($format)) { $format = '%.3f%s'; } if ($microtime >= 1) { $unit = 's'; $time = round($microtime, $round); } else { $unit = 'ms'; $time = round($microtime*1000); $format = preg_replace('/(%.[\d]+f)/', '%d', $format); } return sprintf($format, $time, $unit); } } $bench = new Ubench; $testSum = 0; $bench->start(); // Execute some code for ($i = 0; $i < 1000000; $i++) { $j= $i; } $bench->end(); // Get elapsed time and memory echo "[" . $bench->getTime(); echo " | " . $bench->getTime(true); // elapsed microtime in float echo " | " . $bench->getTime(false, '%d%s') . "]"; echo "\r\n[" . $bench->getMemoryPeak(); echo " | " . $bench->getMemoryPeak(true); // memory peak in bytes echo " | " . $bench->getMemoryPeak(false, '%.3f%s') . "]"; // Returns the memory usage at the end mark echo "\r\n---\r\n" . $bench->getMemoryUsage(); exit(); ?>

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)
7.4.10.0100.01714.96
7.4.00.0000.03215.53
7.3.130.0070.02415.15
7.3.120.0140.02115.11
7.3.110.0090.02515.02
7.3.100.0030.02514.92
7.3.90.0040.01515.24
7.3.80.0070.02014.88
7.3.70.0090.01814.94
7.3.60.0070.01714.87
7.3.50.0100.01615.17
7.3.40.0060.02115.16
7.3.30.0030.02515.20
7.3.20.0040.02217.13
7.3.10.0070.02016.88
7.3.00.0050.02016.70
7.2.260.0070.02815.31
7.2.250.0060.02215.30
7.2.240.0030.02014.98
7.2.230.0100.01315.55
7.2.220.0030.02215.31
7.2.210.0160.01315.36
7.2.200.0000.02715.47
7.2.190.0030.02315.27
7.2.180.0000.02715.11
7.2.170.0100.01415.25
7.2.160.0000.02515.45
7.2.150.0070.02016.98
7.2.140.0090.01616.87
7.2.130.0030.01916.90
7.2.120.0060.01817.10
7.2.110.0090.02217.01
7.2.100.0100.02017.00
7.2.90.0050.01916.96
7.2.80.0050.01916.94
7.2.70.0050.02317.03
7.2.60.0070.01917.02
7.2.50.0110.01917.09
7.2.40.0090.01817.08
7.2.30.0080.02017.08
7.2.20.0080.02217.02
7.2.10.0100.02017.02
7.2.00.0110.01817.14
7.1.330.0000.05315.97
7.1.320.0030.04315.82
7.1.310.0130.04016.07
7.1.300.0070.04115.83
7.1.290.0100.04115.82
7.1.280.0000.05416.00
7.1.270.0000.05216.04
7.1.260.0030.04716.18
7.1.250.0070.04416.04
7.1.240.0070.05215.98
7.1.230.0060.04216.03
7.1.220.0030.05016.09
7.1.210.0070.06116.00
7.1.200.0000.04815.75
7.1.190.0030.04815.70
7.1.180.0100.04316.00
7.1.170.0070.04216.13
7.1.160.0000.04815.96
7.1.150.0000.04916.08
7.1.140.0030.05216.09
7.1.130.0070.05816.08
7.1.120.0030.04716.00
7.1.110.0030.05915.98
7.1.100.0070.04516.20
7.1.90.0030.04516.09
7.1.80.0100.03916.10
7.1.70.0050.03116.65
7.1.60.0080.03817.68
7.1.50.0070.03916.69
7.1.40.0030.04615.91
7.1.30.0000.04515.82
7.1.20.0030.04715.71
7.1.10.0000.05415.94
7.1.00.0070.06719.14
7.0.330.0060.04515.68
7.0.320.0030.04915.61
7.0.310.0030.04115.71
7.0.300.0070.04815.66
7.0.290.0100.04315.26
7.0.280.0070.05415.51
7.0.270.0070.05115.71
7.0.260.0100.04415.54
7.0.250.0000.05015.71
7.0.240.0030.04815.74
7.0.230.0100.04215.71
7.0.220.0000.06115.65
7.0.210.0070.04715.79
7.0.200.0400.02815.32
7.0.190.0000.05215.75
7.0.180.0100.04015.60
7.0.170.0070.04615.74
7.0.160.0030.05715.62
7.0.150.0070.04515.79
7.0.140.0030.05415.60
7.0.130.0070.04715.83
7.0.120.0060.04915.75
7.0.110.0130.03815.68
7.0.100.0170.06117.78
7.0.90.0050.07217.58
7.0.80.0080.07417.67
7.0.70.0120.06817.65
7.0.60.0120.07317.68
7.0.50.0120.06618.00
7.0.40.0100.06516.80
7.0.30.0050.08616.75
7.0.20.0050.06316.80
7.0.10.0080.07816.92
7.0.00.0080.07216.88
5.6.400.0000.11514.84
5.6.390.0070.10914.21
5.6.380.0100.12214.61
5.6.370.0070.11214.54
5.6.360.0100.10914.47
5.6.350.0030.12214.57
5.6.340.0030.12114.74
5.6.330.0030.11414.45
5.6.320.0070.11914.63
5.6.310.0000.12414.62
5.6.300.0030.11414.65
5.6.290.0030.11514.61
5.6.280.0050.09117.83
5.6.270.0100.11014.36
5.6.260.0070.11314.49
5.6.250.0080.12017.57
5.6.240.0070.11717.69
5.6.230.0100.12417.74
5.6.220.0120.10817.57
5.6.210.0050.12617.51
5.6.200.0080.11817.71
5.6.190.0100.12417.87
5.6.180.0070.13817.81
5.6.170.0080.12517.75
5.6.160.0030.12817.85
5.6.150.0070.12317.80
5.6.140.0070.13717.89
5.6.130.0100.12517.89
5.6.120.0120.11517.93
5.6.110.0030.12817.64
5.6.100.0070.12317.81
5.6.90.0130.12617.84
5.6.80.0050.12217.48
5.6.70.0070.11417.31
5.6.60.0030.12617.39
5.6.50.0030.12717.44
5.6.40.0030.12817.32
5.6.30.0170.12017.48
5.6.20.0030.09917.41
5.6.10.0070.12317.44
5.6.00.0100.12317.52
5.5.380.0100.11417.52
5.5.370.0070.10317.38
5.5.360.0100.12317.55
5.5.350.0050.12317.51
5.5.340.0070.12917.68
5.5.330.0000.13117.54
5.5.320.0080.14617.69
5.5.310.0080.12517.72
5.5.300.0070.12617.75
5.5.290.0070.12617.78
5.5.280.0000.13517.72
5.5.270.0020.11817.63
5.5.260.0080.11817.60
5.5.250.0080.11317.60
5.5.240.0100.12317.41
5.5.230.0030.13317.17
5.5.220.0030.12617.24
5.5.210.0050.13017.39
5.5.200.0050.12517.29
5.5.190.0070.12217.35
5.5.180.0080.12317.24
5.5.170.0030.12014.41
5.5.160.0050.12817.20
5.5.150.0080.12017.23
5.5.140.0120.11217.26
5.5.130.0130.10917.24
5.5.120.0000.13217.17
5.5.110.0050.11717.43
5.5.100.0030.12317.34
5.5.90.0050.12517.08
5.5.80.0070.12517.15
5.5.70.0050.12217.15
5.5.60.0080.12217.32
5.5.50.0080.12517.21
5.5.40.0080.11317.20
5.5.30.0070.13217.09
5.5.20.0050.12517.28
5.5.10.0030.13417.14
5.5.00.0050.12717.02
5.4.450.0030.13015.30
5.4.440.0050.12915.44
5.4.430.0070.12615.45
5.4.420.0070.11615.26
5.4.410.0050.12015.37
5.4.400.0030.12515.26
5.4.390.0050.11915.07
5.4.380.0120.11815.20
5.4.370.0030.12015.07
5.4.360.0050.11815.19
5.4.350.0080.12315.29
5.4.340.0050.11815.05
5.4.330.0030.11811.27
5.4.320.0070.11615.25
5.4.310.0000.13015.25
5.4.300.0100.12215.23
5.4.290.0020.13215.19
5.4.280.0120.12215.10
5.4.270.0050.12015.12
5.4.260.0020.12615.22
5.4.250.0030.12114.93
5.4.240.0070.13315.25
5.4.230.0050.12215.30
5.4.220.0080.12715.16
5.4.210.0070.12215.22
5.4.200.0080.13114.96
5.4.190.0050.11915.10
5.4.180.0100.11515.08
5.4.170.0080.11415.11
5.4.160.0070.10315.17
5.4.150.0030.10615.06
5.4.140.0020.11113.82
5.4.130.0020.09413.73
5.4.120.0020.09613.75
5.4.110.0050.12613.81
5.4.100.0070.10713.74
5.4.90.0070.12213.96
5.4.80.0020.09813.85
5.4.70.0020.10713.74
5.4.60.0020.12213.88
5.4.50.0070.11613.79
5.4.40.0020.09513.73
5.4.30.0000.09613.80
5.4.20.0000.10713.93
5.4.10.0020.11913.78
5.4.00.0020.09713.51
5.3.290.0030.16014.81
5.3.280.0200.11714.64
5.3.270.0030.15314.75
5.3.260.0070.13014.65
5.3.250.0100.11014.68
5.3.240.0070.09314.65
5.3.230.0000.09314.68
5.3.220.0000.08714.74
5.3.210.0000.08714.61
5.3.200.0000.12714.73
5.3.190.0130.09314.65
5.3.180.0030.08014.64
5.3.170.0130.08314.64
5.3.160.0030.08314.72
5.3.150.0030.14314.74
5.3.140.0000.08714.59
5.3.130.0030.08314.71
5.3.120.0070.09314.71
5.3.110.0000.10014.70
5.3.100.0000.09014.06
5.3.90.0000.08714.07
5.3.80.0030.08314.15
5.3.70.0000.09714.06
5.3.60.0000.08014.10
5.3.50.0000.08714.12
5.3.40.0100.08714.04
5.3.30.0000.08713.88
5.3.20.0100.07713.71
5.3.10.0030.08313.58
5.3.00.0070.12013.57
5.2.170.0000.03012.17
5.2.160.0030.02712.17
5.2.150.0000.03312.17
5.2.140.0030.03012.17
5.2.130.0000.03012.17
5.2.120.0000.03012.17
5.2.110.0130.05712.17
5.2.100.0070.06012.17
5.2.90.0070.06012.17
5.2.80.0000.07012.17
5.2.70.0070.05712.17
5.2.60.0070.03312.17
5.2.50.0030.06312.17
5.2.40.0100.05012.17
5.2.30.0000.04712.17
5.2.20.0030.06712.17
5.2.10.0030.05312.17
5.2.00.0030.06012.17
5.1.60.0030.05312.17
5.1.50.0000.05712.17
5.1.40.0100.05012.17
5.1.30.0100.04012.17
5.1.20.0030.05012.17
5.1.10.0070.05712.17
5.1.00.0030.04012.17
5.0.50.0070.04312.17
5.0.40.0030.04312.17
5.0.30.0100.05712.17
5.0.20.0070.03312.17
5.0.10.0000.04712.17
5.0.00.0070.06012.17
4.4.90.0030.03012.17
4.4.80.0000.03712.17
4.4.70.0070.02712.17
4.4.60.0030.03712.17
4.4.50.0100.02712.17
4.4.40.0070.03012.17
4.4.30.0030.03312.17
4.4.20.0000.03712.17
4.4.10.0030.02712.17
4.4.00.0000.05312.17
4.3.110.0030.03312.17
4.3.100.0000.03712.17
4.3.90.0030.02712.17
4.3.80.0000.04712.17
4.3.70.0070.03012.17
4.3.60.0000.03012.17
4.3.50.0070.02012.17
4.3.40.0030.05312.17
4.3.30.0070.03012.17
4.3.20.0000.02012.17
4.3.10.0000.03312.17
4.3.00.0000.03312.17

preferences:
65.65 ms | 403 KiB | 5 Q