3v4l.org

run code in 300+ PHP versions simultaneously
<?php namespace Ampersand\DevTest\BasicOop; interface NumberInterface { /** * Adds n to this number * * @param int $n The amount to add to this number * @return int The new integer value of this number */ public function add($n); /** * Subtracts n from this number * * @param int $n The amount to subtract from this number * @return int The new integer value of this number */ public function subtract($n); /** * Multiplies this number by n * * @param int $n The amount to multiply this number by * @return int The new integer value of this number */ public function multiply($n); /** * Divides this number by n * * @param int $n The amount to divide this number by * @return int The new integer value of this number */ public function divide($n); /** * Returns the integer value of this number * * @return int The current integer value of this number */ public function toInt(); } class NumberTest { public function testConstruct() { $n = new Number; $this->assertEquals(0, $n->toInt()); $n = new Number(0); $this->assertEquals(0, $n->toInt()); $n = new Number(3); $this->assertEquals(3, $n->toInt()); } public function testAdd() { $n = new Number; $n->add(5); $this->assertEquals(5, $n->toInt()); $n->add(-7); $this->assertEquals(-2, $n->toInt()); } public function testSubtract() { $n = new Number; $n->subtract(8); $this->assertEquals(-8, $n->toInt()); $n->subtract(-10); $this->assertEquals(2, $n->toInt()); } public function testMultiply() { $n = new Number(1); $n->multiply(10); $this->assertEquals(10, $n->toInt()); $n->multiply(6); $this->assertEquals(60, $n->toInt()); } public function testDivide() { $n = new Number(100); $n->divide(5); $this->assertEquals(20, $n->toInt()); $n->divide(5); $this->assertEquals(4, $n->toInt()); $hasThrownEx = false; try { $n->divide(0); } catch (\InvalidArgumentException $e) { $hasThrownEx = true; } $this->assertEquals(true, $hasThrownEx); } private function assertEquals($expected, $actual) { if ($expected !== $actual) { echo "\n"; var_dump($actual); echo ' does not match expected '; var_dump($expected); echo "\n"; } else { echo '.'; } } } class Number implements NumberInterface { private $value; public function __construct($value = 0) { $this->value = $value; } public function add($value) { $this->value += $value; return $this->value; } public function subtract($value) { $this->value -= $value; return $this->value; } public function multiply($value) { $this->value *= $value; return $this->value; } public function divide($value) { if (0 === $value) { throw new \InvalidArgumentException; } $this->value /= $value; return $this->value; } public function toInt() { return $this->value; } } $test = new NumberTest; $test->testConstruct(); $test->testAdd(); $test->testSubtract(); $test->testMultiply(); $test->testDivide();

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.3.60.0070.00718.31
8.3.50.0160.00522.00
8.3.40.0110.00718.96
8.3.30.0070.00719.21
8.3.20.0080.00020.38
8.3.10.0040.00420.66
8.3.00.0070.00417.60
8.2.180.0070.00716.88
8.2.170.0150.00622.96
8.2.160.0100.00320.39
8.2.150.0000.00824.18
8.2.140.0000.00824.66
8.2.130.0050.00326.16
8.2.120.0040.00422.03
8.2.110.0030.00622.30
8.2.100.0090.00317.78
8.2.90.0030.00619.17
8.2.80.0000.00817.97
8.2.70.0090.00017.63
8.2.60.0000.00817.93
8.2.50.0060.00318.07
8.2.40.0000.00818.34
8.2.30.0000.00719.39
8.2.20.0040.00417.77
8.2.10.0030.00518.23
8.2.00.0000.00817.93
8.1.280.0150.00025.92
8.1.270.0080.00022.17
8.1.260.0000.00826.35
8.1.250.0050.00228.09
8.1.240.0060.00323.84
8.1.230.0040.00719.28
8.1.220.0000.00817.78
8.1.210.0080.00018.77
8.1.200.0030.00617.60
8.1.190.0040.00417.47
8.1.180.0080.00018.10
8.1.170.0050.00318.71
8.1.160.0040.00422.06
8.1.150.0070.00018.98
8.1.140.0030.00617.44
8.1.130.0030.00517.87
8.1.120.0040.00417.47
8.1.110.0030.00517.59
8.1.100.0080.00017.52
8.1.90.0080.00017.47
8.1.80.0050.00317.48
8.1.70.0030.00317.51
8.1.60.0030.00617.63
8.1.50.0060.00317.63
8.1.40.0040.00417.58
8.1.30.0040.00417.61
8.1.20.0000.00817.63
8.1.10.0080.00017.53
8.1.00.0000.00717.63
8.0.300.0000.00718.77
8.0.290.0050.00316.88
8.0.280.0000.00718.58
8.0.270.0000.00917.33
8.0.260.0000.00717.40
8.0.250.0040.00417.00
8.0.240.0000.00817.00
8.0.230.0000.00716.96
8.0.220.0070.00017.02
8.0.210.0070.00016.91
8.0.200.0000.00717.00
8.0.190.0070.00016.96
8.0.180.0070.00017.03
8.0.170.0040.00417.06
8.0.160.0000.00716.97
8.0.150.0050.00216.86
8.0.140.0050.00216.86
8.0.130.0030.00313.47
8.0.120.0050.00316.96
8.0.110.0000.00716.93
8.0.100.0030.00517.14
8.0.90.0040.00417.05
8.0.80.0040.01117.02
8.0.70.0000.00917.04
8.0.60.0040.00416.99
8.0.50.0000.00716.97
8.0.30.0070.01416.98
8.0.20.0090.01217.40
8.0.10.0040.00416.96
8.0.00.0100.00816.86
7.4.330.0000.00515.00
7.4.320.0040.00416.52
7.4.300.0040.00416.57
7.4.290.0030.00316.44
7.4.280.0040.00416.70
7.4.270.0070.00016.61
7.4.260.0100.00016.67
7.4.250.0050.00316.66
7.4.240.0040.00316.62
7.4.230.0000.00716.70
7.4.220.0040.01516.68
7.4.210.0070.00716.59
7.4.200.0050.00216.59
7.4.160.0110.01116.62
7.4.150.0070.01017.40
7.4.140.0130.00617.86
7.4.130.0050.01216.65
7.4.120.0050.01316.56
7.4.110.0060.01016.62
7.4.100.0110.00716.70
7.4.90.0100.00716.60
7.4.80.0070.01019.39
7.4.70.0130.00316.53
7.4.60.0170.00016.63
7.4.50.0040.00416.49
7.4.40.0070.01016.63
7.4.30.0080.00816.55
7.4.10.0090.00914.86
7.4.00.0070.01115.19
7.3.330.0030.00313.49
7.3.320.0050.00013.52
7.3.310.0030.00316.51
7.3.300.0000.00816.62
7.3.290.0070.01316.48
7.3.280.0100.00716.49
7.3.270.0090.00917.40
7.3.260.0090.00916.52
7.3.250.0080.01516.68
7.3.240.0090.00916.52
7.3.230.0090.00616.52
7.3.210.0030.01416.60
7.3.200.0070.01119.39
7.3.190.0120.00616.45
7.3.180.0090.00616.47
7.3.170.0140.00716.58
7.3.160.0060.01116.76
7.3.130.0110.00714.93
7.3.120.0110.00714.78
7.3.110.0040.01514.77
7.3.100.0120.00315.19
7.3.90.0040.00715.07
7.3.80.0070.00714.99
7.3.70.0030.01015.07
7.3.60.0060.00915.06
7.3.50.0100.00314.77
7.3.40.0060.00314.97
7.3.30.0000.01515.06
7.3.20.0100.00416.47
7.3.10.0100.00016.47
7.3.00.0060.00616.66
7.2.330.0060.01216.55
7.2.320.0120.00616.84
7.2.310.0030.01816.72
7.2.300.0080.00816.57
7.2.290.0120.00616.75
7.2.260.0040.01115.01
7.2.250.0090.00915.14
7.2.240.0000.01615.21
7.2.230.0070.00715.02
7.2.220.0000.01015.36
7.2.210.0030.01315.09
7.2.200.0000.01215.00
7.2.190.0000.01215.24
7.2.180.0000.01815.16
7.2.170.0110.00315.15
7.2.160.0030.01414.79
7.2.150.0000.01717.01
7.2.140.0090.00616.84
7.2.130.0090.00616.99
7.2.120.0040.00816.89
7.2.110.0060.00616.99
7.2.100.0070.00716.64
7.2.90.0070.01317.00
7.2.80.0000.01416.80
7.2.70.0130.00316.94
7.2.60.0070.00716.98
7.2.50.0030.00916.84
7.2.40.0090.00617.05
7.2.30.0160.00317.03
7.2.20.0110.00317.02
7.2.10.0000.01617.02
7.2.00.0070.00717.08
7.1.330.0060.00915.95
7.1.320.0060.00615.88
7.1.310.0040.00415.79
7.1.300.0070.00315.82
7.1.290.0060.00615.73
7.1.280.0040.01115.86
7.1.270.0040.00815.89
7.1.260.0000.00915.88
7.1.250.0090.00615.65
7.1.240.0070.00415.93
7.1.230.0060.00615.94
7.1.220.0030.01415.80
7.1.210.0040.01415.73
7.1.200.0060.00315.72
7.1.190.0060.00915.77
7.1.180.0040.00915.80
7.1.170.0060.00915.59
7.1.160.0000.01215.58
7.1.150.0030.01415.50
7.1.140.0070.01015.90
7.1.130.0070.00315.71
7.1.120.0030.01015.89
7.1.110.0030.00915.59
7.1.100.0000.01715.77
7.1.90.0000.01815.79
7.1.80.0030.01315.94
7.1.70.0100.00516.47
7.1.60.0080.00616.67
7.1.50.0050.01216.50
7.1.40.0080.00616.00
7.1.30.0000.01815.73
7.1.20.0030.00715.74
7.1.10.0070.00715.79
7.1.00.0070.04218.95
7.0.330.0140.00315.46
7.0.320.0060.00315.43
7.0.310.0000.01115.41
7.0.300.0030.00915.43
7.0.290.0120.00315.30
7.0.280.0000.01815.38
7.0.270.0070.00315.16
7.0.260.0000.00915.43
7.0.250.0070.00315.38
7.0.240.0000.01515.40
7.0.230.0070.01015.23
7.0.220.0030.01215.14
7.0.210.0120.00015.29
7.0.200.0070.00816.11
7.0.190.0090.00915.29
7.0.180.0070.01015.48
7.0.170.0030.01015.45
7.0.160.0060.00615.40
7.0.150.0080.00815.25
7.0.140.0110.02318.57
7.0.130.0030.01015.66
7.0.120.0060.01015.45
7.0.110.0070.00715.56
7.0.100.0040.01115.55
7.0.90.0000.01015.46
7.0.80.0080.00415.39
7.0.70.0070.00715.57
7.0.60.0070.02717.57
7.0.50.0050.03816.70
7.0.40.0060.02916.66
7.0.30.0180.03816.69
7.0.20.0110.03816.86
7.0.10.0120.04216.73
7.0.00.0030.04916.79
5.6.400.0080.00814.30
5.6.390.0030.01414.43
5.6.380.0120.00614.89
5.6.370.0000.01114.48
5.6.360.0030.01214.70
5.6.350.0000.01414.82
5.6.340.0130.00314.27
5.6.330.0120.00314.62
5.6.320.0060.01114.77
5.6.310.0030.01014.49
5.6.300.0070.00714.66
5.6.290.0040.00714.39
5.6.280.0070.03817.82
5.6.270.0080.00814.27
5.6.260.0070.00714.52
5.6.250.0050.00514.51
5.6.240.0060.00914.34
5.6.230.0000.01414.57
5.6.220.0080.00414.45
5.6.210.0090.02217.62
5.6.200.0050.04816.47
5.6.190.0030.04817.50
5.6.180.0160.04317.48
5.6.170.0150.04117.56
5.6.160.0100.04017.68
5.6.150.0040.02216.38
5.6.140.0050.04716.29
5.6.130.0090.02816.49
5.6.120.0070.02717.72
5.6.110.0050.04417.77
5.6.100.0050.03217.67
5.6.90.0020.02717.77
5.6.80.0060.04317.40
5.6.70.0070.00714.38
5.6.60.0030.00514.25
5.6.50.0040.00714.39
5.6.40.0040.01414.46
5.6.30.0070.01014.33
5.6.20.0070.00414.30
5.6.10.0090.00314.54
5.6.00.0060.00614.57
5.5.380.0030.01114.52
5.5.370.0030.01414.53
5.5.360.0000.01114.36
5.5.350.0190.04017.47
5.5.340.0050.02416.11
5.5.330.0080.02317.36
5.5.320.0150.03317.31
5.5.310.0230.03317.38
5.5.300.0090.03016.29
5.5.290.0070.04416.36
5.5.280.0070.02917.79
5.5.270.0030.02717.70
5.5.260.0100.04317.63
5.5.250.0050.03817.59
5.5.240.0070.03817.21
5.5.230.0030.00614.39
5.5.220.0070.00714.41
5.5.210.0030.01014.36
5.5.200.0000.01514.59
5.5.190.0030.01014.04
5.5.180.0060.00314.25
5.5.170.0000.01614.26
5.5.160.0040.00814.55
5.5.150.0070.00714.52
5.5.140.0090.00614.31
5.5.130.0040.01114.14
5.5.120.0000.01514.04
5.5.110.0030.00714.30
5.5.100.0110.00314.47
5.5.90.0060.01214.50
5.5.80.0030.01014.59
5.5.70.0030.00614.50
5.5.60.0030.01014.17
5.5.50.0040.01114.46
5.5.40.0030.01314.46
5.5.30.0030.01414.32
5.5.20.0080.00814.02
5.5.10.0040.01114.45
5.5.00.0030.00914.47
5.4.450.0100.02915.63
5.4.440.0080.02815.58
5.4.430.0170.02515.48
5.4.420.0220.02715.63
5.4.410.0180.02615.60
5.4.400.0160.02015.43
5.4.390.0120.02615.43
5.4.380.0120.03515.27
5.4.370.0130.03315.29
5.4.360.0150.04415.25
5.4.350.0130.03315.28
5.4.340.0130.03415.15
5.4.330.0000.00811.78
5.4.320.0040.02312.16
5.4.310.0070.02012.16
5.4.300.0070.01912.15
5.4.290.0040.02312.15
5.4.280.0050.02212.10
5.4.270.0040.02412.10
5.4.260.0060.02312.10
5.4.250.0070.02312.10
5.4.240.0030.02512.10
5.4.230.0030.02312.10
5.4.220.0060.02112.10
5.4.210.0040.02112.10
5.4.200.0070.02212.10
5.4.190.0040.02212.10
5.4.180.0070.02012.10
5.4.170.0080.01912.10
5.4.160.0080.02112.10
5.4.150.0040.02112.10
5.4.140.0040.02311.94
5.4.130.0020.02411.93
5.4.120.0050.02211.91
5.4.110.0040.02211.91
5.4.100.0040.02311.91
5.4.90.0050.02211.91
5.4.80.0040.02011.91
5.4.70.0060.02011.91
5.4.60.0060.02011.91
5.4.50.0050.02211.91
5.4.40.0020.03011.90
5.4.30.0050.02511.90
5.4.20.0100.02411.90
5.4.10.0070.01911.90
5.4.00.0080.02011.64
5.3.290.0060.03912.80
5.3.280.0060.04312.74
5.3.270.0090.04712.75
5.3.260.0100.04312.75
5.3.250.0110.04112.75
5.3.240.0080.04312.75
5.3.230.0070.04112.74
5.3.220.0070.03812.71
5.3.210.0030.04412.71
5.3.200.0080.03512.71
5.3.190.0090.04212.71
5.3.180.0110.03612.71
5.3.170.0090.03712.71
5.3.160.0050.03612.71
5.3.150.0070.03912.71
5.3.140.0060.03712.70
5.3.130.0040.04312.69
5.3.120.0070.05112.70
5.3.110.0090.05112.70
5.3.100.0040.04412.17
5.3.90.0080.03912.16
5.3.80.0030.04012.15
5.3.70.0050.04012.15
5.3.60.0060.03712.13
5.3.50.0040.03812.08
5.3.40.0070.03712.08
5.3.30.0010.04012.04
5.3.20.0050.03711.82
5.3.10.0030.03711.79
5.3.00.0050.03611.77
5.2.170.0040.0309.18
5.2.160.0040.0299.18
5.2.150.0030.0319.18
5.2.140.0040.0309.18
5.2.130.0040.0299.14
5.2.120.0050.0279.14
5.2.110.0010.0339.15
5.2.100.0080.0259.14
5.2.90.0050.0299.14
5.2.80.0060.0349.14
5.2.70.0080.0279.14
5.2.60.0060.0319.09
5.2.50.0010.0339.07
5.2.40.0050.0299.04
5.2.30.0040.0309.02
5.2.20.0060.0389.01
5.2.10.0070.0288.93
5.2.00.0060.0298.78
5.1.60.0060.0338.07
5.1.50.0080.0378.07
5.1.40.0040.0268.05
5.1.30.0070.0248.40
5.1.20.0040.0368.42
5.1.10.0040.0278.14
5.1.00.0020.0278.15
5.0.50.0050.0246.63
5.0.40.0030.0236.48
5.0.30.0030.0356.30
5.0.20.0020.0216.27
5.0.10.0020.0216.25
5.0.00.0020.0326.23
4.4.90.0020.0164.78
4.4.80.0040.0144.75
4.4.70.0020.0154.75
4.4.60.0050.0124.75
4.4.50.0020.0164.77
4.4.40.0040.0234.71
4.4.30.0030.0154.76
4.4.20.0030.0154.84
4.4.10.0020.0164.85
4.4.00.0020.0264.76
4.3.110.0030.0154.67
4.3.100.0010.0164.66
4.3.90.0020.0154.64
4.3.80.0070.0244.59
4.3.70.0030.0144.63
4.3.60.0030.0164.63
4.3.50.0030.0164.63
4.3.40.0040.0234.54
4.3.30.0030.0153.29
4.3.20.0020.0163.27
4.3.10.0010.0163.22
4.3.00.0100.01316.72

preferences:
47.71 ms | 401 KiB | 5 Q