3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Product { protected $price; protected $discount; private function getPrice() { return $this->price; } public function setPrice($price, $type, $start_amount) { $this->price = new Price($price); $this->price->setType($type); $this->price->setFirstPay($start_amount); } private function getDiscount() { return $this->discount; } public function setDiscount($discount, $type) { $this->discount = new Discount($discount); $this->discount->setType($type); } public function getCost() { $price = $this->getPrice(); $discount = $this->getDiscount(); // calculate cost switch ($price->getType()) { case 0: // one-off price $price = $price->getValue(); break; case 1: // subscription - it is considered to be an year subscription by default $price = round(($price->getValue() / 12), 2); break; case 2: // both $price = $price->getFirstPay() + round(($price->getValue() / 12), 2); break; } // calculate additional discount switch ($discount->getType()) { case 0: // one-off price $discount = $discount->getValue(); break; case 1: // subscription - it is considered to be an year subscription by default $discount = round(($discount->getValue() / 12), 2); break; } return $price-$discount; } } class Price { protected $type; // 0 - one-off price, 1 - subscription/monthly price, 2 - combination of previous two; protected $value; protected $first_pay; function __construct($value) { if (is_numeric($value)) { $this->value = round(floatval($value), 2); } else { $this->value = 0; } } public function getType() { return $this->type; } public function setType($type) { if (is_numeric($type) && in_array(intval($type), array(0, 1, 2))) { $this->type = intval($type); } else { $this->type = 0; } } public function getValue() { return $this->value; } public function getFirstPay() { return $this->first_pay; } public function setFirstPay($amount) { if (is_numeric($amount)) { $this->first_pay = round(floatval($amount), 2); } else { $this->first_pay = 0; } } } class Discount extends Price { /* this is considered to be a fixed value and not a percentage */ } class Shopcart { protected $shopping_list; function __construct($products) { $this->shopping_list[] = $products; } public function getCurrentCost() { $cost = 0; foreach ($this->shopping_list as $item) { $cost += $item->getCost(); } return $cost; } } $p1 = new Product(); $p1->setPrice(36, 1, 0); $p1->setDiscount(3); $p2 = new Product(); $p2->setPrice(44, 1, 10); $p2->setDiscount(24, 1); $s = new Shopcart(array($p1, $p2)); $s->getCurrentCost();

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.01118.53
8.3.50.0100.00821.10
8.3.40.0090.01218.80
8.3.30.0130.00318.96
8.3.20.0080.00020.32
8.3.10.0040.00423.83
8.3.00.0040.00422.51
8.2.180.0150.00318.43
8.2.170.0040.01122.96
8.2.160.0090.00620.53
8.2.150.0040.00424.18
8.2.140.0040.00424.66
8.2.130.0080.00026.16
8.2.120.0100.00017.63
8.2.110.0030.00719.31
8.2.100.0090.00318.03
8.2.90.0080.00019.40
8.2.80.0000.00817.97
8.2.70.0060.00617.75
8.2.60.0080.00017.93
8.2.50.0060.00318.10
8.2.40.0080.00021.24
8.2.30.0050.00319.99
8.2.20.0030.00517.88
8.2.10.0000.00718.27
8.2.00.0080.00018.11
8.1.280.0040.01125.92
8.1.270.0000.00820.27
8.1.260.0050.00326.35
8.1.250.0040.00428.09
8.1.240.0030.00622.72
8.1.230.0040.00817.70
8.1.220.0040.00417.74
8.1.210.0030.00618.77
8.1.200.0060.00317.25
8.1.190.0040.00417.35
8.1.180.0050.00318.10
8.1.170.0000.00818.54
8.1.160.0040.00422.11
8.1.150.0040.00419.05
8.1.140.0040.00417.56
8.1.130.0000.00717.81
8.1.120.0050.00317.67
8.1.110.0080.00017.45
8.1.100.0050.00317.44
8.1.90.0000.00717.45
8.1.80.0060.00317.61
8.1.70.0000.00717.57
8.1.60.0040.00417.60
8.1.50.0030.00517.53
8.1.40.0040.00417.66
8.1.30.0040.00417.70
8.1.20.0090.00017.67
8.1.10.0000.00817.58
8.1.00.0000.00817.59
8.0.300.0040.00418.77
8.0.290.0050.00316.88
8.0.280.0000.00718.41
8.0.270.0050.00217.36
8.0.260.0040.00417.30
8.0.250.0040.00417.04
8.0.240.0030.00317.14
8.0.230.0030.00317.13
8.0.220.0070.00017.09
8.0.210.0040.00417.00
8.0.200.0000.00717.13
8.0.190.0030.00617.15
8.0.180.0000.00817.05
8.0.170.0050.00317.11
8.0.160.0050.00317.01
8.0.150.0040.00416.99
8.0.140.0030.00817.05
8.0.130.0080.00013.58
8.0.120.0000.00717.04
8.0.110.0000.00817.09
8.0.100.0000.00716.92
8.0.90.0040.00416.95
8.0.80.0130.00317.04
8.0.70.0030.00517.11
8.0.60.0000.00816.91
8.0.50.0040.00417.13
8.0.30.0110.00817.10
8.0.20.0060.01217.48
8.0.10.0040.00417.05
8.0.00.0090.01117.02
7.4.330.0000.00615.21
7.4.320.0070.00016.71
7.4.300.0030.00316.76
7.4.290.0030.00316.61
7.4.280.0040.00416.53
7.4.270.0030.00316.57
7.4.260.0000.00716.64
7.4.250.0040.00416.64
7.4.240.0020.00516.71
7.4.230.0080.00016.60
7.4.220.0110.00916.63
7.4.210.0090.00616.57
7.4.200.0000.00716.51
7.4.160.0070.01016.45
7.4.150.0060.01117.40
7.4.140.0130.00917.86
7.4.130.0170.00516.54
7.4.120.0080.01216.76
7.4.110.0150.00316.65
7.4.100.0180.00616.76
7.4.90.0070.01116.61
7.4.80.0090.00919.39
7.4.70.0100.00716.51
7.4.60.0120.00416.69
7.4.50.0030.00616.52
7.4.40.0130.00316.59
7.4.30.0190.00416.67
7.4.00.0070.01115.10
7.3.330.0000.00613.59
7.3.320.0000.00513.43
7.3.310.0030.00316.46
7.3.300.0000.00716.48
7.3.290.0080.00916.56
7.3.280.0070.01216.53
7.3.270.0130.00617.40
7.3.260.0090.00916.80
7.3.250.0090.01216.59
7.3.240.0040.01516.55
7.3.230.0040.01316.63
7.3.210.0030.01416.62
7.3.200.0030.01719.39
7.3.190.0030.01316.67
7.3.180.0130.00316.71
7.3.170.0110.00616.62
7.3.160.0070.01016.56
7.2.330.0090.00916.84
7.2.320.0090.00916.66
7.2.310.0090.00916.93
7.2.300.0090.00616.89
7.2.290.0130.00416.85
7.2.60.0080.00816.62
7.2.00.0120.00319.25
7.1.200.0060.00615.57
7.1.100.0170.00718.09
7.1.70.0000.00817.08
7.1.60.0070.01720.03
7.1.50.0100.01317.14
7.1.00.0070.07322.73
7.0.200.0130.01016.83
7.0.100.0270.08020.22
7.0.90.0070.08320.16
7.0.80.0130.08020.20
7.0.70.0400.07320.14
7.0.60.0070.07720.19
7.0.50.0070.07320.50
7.0.40.0170.06320.28
7.0.30.0000.08720.34
7.0.20.0130.08020.37
7.0.10.0070.04720.21
7.0.00.0100.08320.27
5.6.280.0070.03021.27
5.6.250.0070.08320.88
5.6.240.0100.06720.89
5.6.230.0030.04720.91
5.6.220.0000.05020.75
5.6.210.0100.03320.87
5.6.200.0130.05021.28
5.6.190.0130.06721.27
5.6.180.0070.06021.18
5.6.170.0100.08021.21
5.6.160.0100.04721.26
5.6.150.0100.08321.30
5.6.140.0130.07321.20
5.6.130.0030.04721.27
5.6.120.0100.07721.25
5.6.110.0030.08021.25
5.6.100.0100.06721.32
5.6.90.0030.05321.34
5.6.80.0130.07020.57
5.6.70.0200.07020.67
5.6.60.0030.03720.73
5.6.50.0070.07320.61
5.6.40.0170.06720.66
5.6.30.0130.07020.62
5.6.20.0070.08020.66
5.6.10.0030.07320.69
5.6.00.0070.05320.55
5.5.380.0100.08020.75
5.5.370.0170.07020.62
5.5.360.0200.05320.60
5.5.350.0170.06720.71
5.5.340.0070.07721.02
5.5.330.0070.04320.97
5.5.320.0070.05020.94
5.5.310.0000.05021.15
5.5.300.0030.04721.01
5.5.290.0200.05321.04
5.5.280.0130.08021.11
5.5.270.0070.06321.02
5.5.260.0130.07320.98
5.5.250.0030.06720.83
5.5.240.0170.06020.43
5.5.230.0030.07320.48
5.5.220.0070.05320.43
5.5.210.0030.08720.36
5.5.200.0070.08320.40
5.5.190.0070.07320.51
5.5.180.0100.07020.43
5.5.160.0100.07020.40
5.5.150.0070.05020.40
5.5.140.0100.07320.36
5.5.130.0100.06320.50
5.5.120.0170.06320.49
5.5.110.0030.09020.48
5.5.100.0000.04720.43
5.5.90.0070.07720.35
5.5.80.0130.06320.38
5.5.70.0030.04720.31
5.5.60.0130.07720.22
5.5.50.0070.05320.21
5.5.40.0070.07320.28
5.5.30.0000.04320.25
5.5.20.0030.04320.16
5.5.10.0000.07720.27
5.5.00.0100.06320.22
5.4.450.0130.04319.60
5.4.440.0130.07719.49
5.4.430.0130.07319.45
5.4.420.0070.08319.49
5.4.410.0130.07719.28
5.4.400.0030.07719.44
5.4.390.0100.04319.42
5.4.380.0030.08019.25
5.4.370.0030.05019.33
5.4.360.0070.07719.31
5.4.350.0070.07719.35
5.4.340.0130.08019.27
5.4.320.0130.07719.21
5.4.310.0200.06019.35
5.4.300.0100.05319.16
5.4.290.0000.05019.36
5.4.280.0200.06719.30
5.4.270.0000.07319.24
5.4.260.0170.06319.23
5.4.250.0030.06019.21
5.4.240.0070.04319.05
5.4.230.0130.07319.41
5.4.220.0030.06319.03
5.4.210.0030.05319.23
5.4.200.0100.04019.30
5.4.190.0130.05019.23
5.4.180.0030.04719.15
5.4.170.0000.04719.25
5.4.160.0170.07019.14
5.4.150.0100.05719.24
5.4.140.0100.03316.58
5.4.130.0100.07016.60
5.4.120.0070.07016.42
5.4.110.0070.07316.63
5.4.100.0070.06016.68
5.4.90.0070.03316.61
5.4.80.0070.07316.57
5.4.70.0100.05316.66
5.4.60.0100.03016.50
5.4.50.0000.04316.62
5.4.40.0070.07016.64
5.4.30.0070.03716.68
5.4.20.0130.06316.57
5.4.10.0100.05316.57
5.4.00.0000.05316.02

preferences:
64.45 ms | 401 KiB | 5 Q