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, 0); $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.0060.01218.68
8.3.50.0080.01021.08
8.3.40.0110.00419.00
8.3.30.0070.00718.93
8.3.20.0040.00420.38
8.3.10.0030.00523.79
8.3.00.0040.00422.46
8.2.180.0090.00918.13
8.2.170.0070.00722.96
8.2.160.0100.01020.52
8.2.150.0000.00824.18
8.2.140.0000.00724.66
8.2.130.0000.00826.16
8.2.120.0060.00317.75
8.2.110.0070.00319.52
8.2.100.0090.00317.85
8.2.90.0040.00419.34
8.2.80.0030.00617.97
8.2.70.0030.00617.72
8.2.60.0000.00817.92
8.2.50.0090.00018.07
8.2.40.0040.00421.32
8.2.30.0000.00819.97
8.2.20.0030.00517.80
8.2.10.0040.00418.23
8.2.00.0040.00418.16
8.1.280.0060.00925.92
8.1.270.0040.00420.37
8.1.260.0050.00326.35
8.1.250.0050.00328.09
8.1.240.0030.00622.66
8.1.230.0060.00617.61
8.1.220.0050.00317.77
8.1.210.0030.00618.77
8.1.200.0030.00617.35
8.1.190.0050.00317.35
8.1.180.0000.00818.10
8.1.170.0000.00818.59
8.1.160.0000.00722.08
8.1.150.0050.00219.00
8.1.140.0050.00317.57
8.1.130.0050.00217.87
8.1.120.0040.00417.54
8.1.110.0000.00817.50
8.1.100.0000.00717.46
8.1.90.0020.00517.43
8.1.80.0070.00017.63
8.1.70.0030.00317.45
8.1.60.0030.00517.61
8.1.50.0000.00717.55
8.1.40.0040.00417.51
8.1.30.0090.00017.82
8.1.20.0000.00817.70
8.1.10.0080.00017.58
8.1.00.0050.00317.66
8.0.300.0050.00518.77
8.0.290.0040.00417.00
8.0.280.0070.00018.61
8.0.270.0040.00417.34
8.0.260.0080.00017.46
8.0.250.0000.00817.11
8.0.240.0070.00017.13
8.0.230.0040.00417.10
8.0.220.0070.00017.11
8.0.210.0000.00817.04
8.0.200.0030.00517.17
8.0.190.0000.00717.14
8.0.180.0080.00017.07
8.0.170.0080.00017.04
8.0.160.0070.00017.09
8.0.150.0000.00817.00
8.0.140.0080.00317.09
8.0.130.0050.00513.49
8.0.120.0060.00317.03
8.0.110.0040.00417.00
8.0.100.0070.00016.89
8.0.90.0020.00516.87
8.0.80.0170.00317.04
8.0.70.0040.00417.02
8.0.60.0040.00417.11
8.0.50.0080.00016.91
8.0.30.0100.00717.17
8.0.20.0100.00917.40
8.0.10.0000.00717.15
8.0.00.0050.01416.78
7.4.330.0000.00515.11
7.4.320.0060.00016.61
7.4.300.0060.00016.76
7.4.290.0040.00416.61
7.4.280.0050.00316.50
7.4.270.0040.00416.70
7.4.260.0000.00816.69
7.4.250.0040.00416.68
7.4.240.0030.00416.68
7.4.230.0030.00516.51
7.4.220.0060.01316.64
7.4.210.0030.01316.71
7.4.200.0000.00816.81
7.4.160.0090.00616.59
7.4.150.0100.00717.40
7.4.140.0160.01017.86
7.4.130.0090.01016.59
7.4.120.0130.01216.61
7.4.110.0130.00416.48
7.4.100.0140.00916.75
7.4.90.0090.00916.71
7.4.80.0000.02119.39
7.4.70.0100.00716.65
7.4.60.0080.00916.75
7.4.50.0000.00916.71
7.4.40.0070.01016.69
7.4.30.0090.00916.65
7.4.10.0100.00716.42
7.4.00.0070.01015.71
7.3.330.0050.00013.56
7.3.320.0000.00513.34
7.3.310.0030.00316.59
7.3.300.0040.00416.56
7.3.290.0040.01116.57
7.3.280.0110.00716.51
7.3.270.0100.00717.40
7.3.260.0090.00916.63
7.3.250.0110.00916.63
7.3.240.0080.00816.64
7.3.230.0100.00716.66
7.3.210.0120.00916.58
7.3.200.0030.01319.39
7.3.190.0100.01416.61
7.3.180.0070.01016.64
7.3.170.0110.00516.64
7.3.160.0100.00716.79
7.3.130.0060.01316.44
7.3.120.0090.00815.86
7.3.110.0040.01315.89
7.3.100.0100.00715.93
7.3.90.0090.00715.74
7.3.80.0050.01115.73
7.3.70.0080.00815.70
7.3.60.0050.00915.85
7.3.50.0050.00915.79
7.3.40.0080.00715.80
7.3.30.0060.00815.93
7.3.20.0060.00717.55
7.3.10.0100.00517.47
7.3.00.0020.01317.57
7.2.330.0100.00716.95
7.2.320.0000.02016.93
7.2.310.0130.01016.86
7.2.300.0100.00717.00
7.2.290.0070.01016.75
7.2.260.0070.01316.77
7.2.250.0170.00716.77
7.2.240.0090.00816.12
7.2.230.0080.00715.99
7.2.220.0070.00716.14
7.2.210.0050.01016.02
7.2.200.0120.00515.89
7.2.190.0110.00415.79
7.2.180.0030.01416.02
7.2.170.0090.00815.93
7.2.160.0080.01015.96
7.2.150.0070.01017.62
7.2.140.0020.01317.59
7.2.130.0050.01317.85
7.2.120.0070.00917.75
7.2.110.0060.00817.71
7.2.100.0090.00817.69
7.2.90.0080.00717.80
7.2.80.0070.01217.80
7.2.70.0080.00517.68
7.2.60.0040.01017.44
7.2.50.0070.00517.62
7.2.40.0050.00717.85
7.2.30.0100.00917.80
7.2.20.0070.00917.87
7.2.10.0090.00717.86
7.2.00.0060.01018.40
7.1.330.0050.00916.54
7.1.320.0030.00916.76
7.1.310.0100.00716.67
7.1.300.0070.00916.63
7.1.290.0030.01216.59
7.1.280.0080.00816.60
7.1.270.0050.00916.48
7.1.260.0070.00816.63
7.1.250.0040.00916.63
7.1.240.0070.01017.49
7.1.230.0070.00717.50
7.1.220.0070.00717.56
7.1.210.0070.00717.34
7.1.200.0080.00816.65
7.1.190.0060.00917.45
7.1.180.0000.01517.40
7.1.170.0070.00717.36
7.1.160.0110.00717.39
7.1.150.0090.00317.46
7.1.140.0030.01317.63
7.1.130.0060.00617.47
7.1.120.0060.01317.34
7.1.110.0080.00617.60
7.1.100.0070.01217.92
7.1.90.0070.00317.54
7.1.80.0100.00617.27
7.1.70.0000.01517.31
7.1.60.0080.01018.70
7.1.50.0050.01217.33
7.1.40.0040.01117.43
7.1.30.0060.00917.60
7.1.20.0110.00417.48
7.1.10.0060.00817.50
7.1.00.0060.04119.83
7.0.330.0000.01316.86
7.0.320.0060.00617.08
7.0.310.0090.00917.00
7.0.300.0080.00816.92
7.0.290.0040.01517.26
7.0.280.0040.01117.11
7.0.270.0000.01217.04
7.0.260.0030.01217.18
7.0.250.0110.00017.21
7.0.240.0060.00317.35
7.0.230.0040.01117.13
7.0.220.0040.01217.16
7.0.210.0070.01117.22
7.0.200.0030.01117.08
7.0.190.0060.00917.07
7.0.180.0000.01617.24
7.0.170.0140.00317.18
7.0.160.0080.00317.19
7.0.150.0030.01017.28
7.0.140.0060.00917.12
7.0.130.0090.00617.02
7.0.120.0000.01217.20
7.0.110.0030.01017.18
7.0.100.0020.02718.70
7.0.90.0140.02318.71
7.0.80.0100.03418.72
7.0.70.0070.03218.60
7.0.60.0080.02818.59
7.0.50.0110.02518.82
7.0.40.0040.02417.77
7.0.30.0050.02617.68
7.0.20.0050.02817.66
7.0.10.0030.02817.66
7.0.00.0030.02817.71
5.6.400.0150.00416.14
5.6.390.0030.01016.02
5.6.380.0110.00316.21
5.6.370.0090.00916.11
5.6.360.0040.01216.21
5.6.350.0040.01516.20
5.6.340.0070.00715.93
5.6.330.0130.00716.17
5.6.320.0090.00616.14
5.6.310.0090.00316.35
5.6.300.0040.01216.27
5.6.290.0090.00616.28
5.6.280.0040.02018.84
5.6.270.0100.00715.97
5.6.260.0060.00916.15
5.6.250.0000.03318.38
5.6.240.0030.03518.61
5.6.230.0030.03018.44
5.6.220.0020.02618.70
5.6.210.0050.02218.48
5.6.200.0050.02718.75
5.6.190.0060.02618.76
5.6.180.0080.02318.64
5.6.170.0060.02518.63
5.6.160.0050.02718.60
5.6.150.0050.02518.75
5.6.140.0050.04718.63
5.6.130.0090.03618.75
5.6.120.0120.03918.78
5.6.110.0060.04418.70
5.6.100.0070.04518.88
5.6.90.0090.02718.72
5.6.80.0120.04018.37
5.6.70.0100.02218.28
5.6.60.0070.04018.30
5.6.50.0100.02818.37
5.6.40.0050.04518.33
5.6.30.0100.04318.38
5.6.20.0070.04718.36
5.6.10.0080.04318.34
5.6.00.0130.03518.37
5.5.380.0100.02718.21
5.5.370.0070.02418.40
5.5.360.0060.02318.38
5.5.350.0080.02118.33
5.5.340.0060.02418.49
5.5.330.0030.04518.52
5.5.320.0060.02818.43
5.5.310.0080.02618.52
5.5.300.0070.03018.50
5.5.290.0080.02118.62
5.5.280.0110.04318.66
5.5.270.0120.03618.66
5.5.260.0070.04718.44
5.5.250.0080.03818.42
5.5.240.0090.02218.29
5.5.230.0100.04218.06
5.5.220.0070.02018.10
5.5.210.0070.04218.26
5.5.200.0080.04118.13
5.5.190.0110.03218.16
5.5.180.0070.04018.16
5.5.170.0120.00316.12
5.5.160.0070.04018.09
5.5.150.0050.03618.28
5.5.140.0020.04418.10
5.5.130.0060.04318.27
5.5.120.0070.05218.30
5.5.110.0070.04518.12
5.5.100.0090.04118.17
5.5.90.0080.04018.06
5.5.80.0110.03518.22
5.5.70.0060.04518.20
5.5.60.0090.04318.06
5.5.50.0110.04118.11
5.5.40.0100.04318.13
5.5.30.0080.04218.03
5.5.20.0100.03818.10
5.5.10.0080.04018.21
5.5.00.0100.03818.03
5.4.450.0030.04016.28
5.4.440.0070.03016.14
5.4.430.0020.04116.31
5.4.420.0080.03116.19
5.4.410.0050.03816.14
5.4.400.0060.04116.09
5.4.390.0100.03015.95
5.4.380.0020.04515.93
5.4.370.0110.03516.15
5.4.360.0030.03315.96
5.4.350.0050.03715.91
5.4.340.0100.03816.02
5.4.330.0040.00412.64
5.4.320.0040.03816.03
5.4.310.0080.03715.89
5.4.300.0020.02915.93
5.4.290.0090.03716.00
5.4.280.0130.03716.05
5.4.270.0080.03515.96
5.4.260.0030.04115.95
5.4.250.0040.04316.07
5.4.240.0080.04015.97
5.4.230.0130.03515.91
5.4.220.0050.04116.08
5.4.210.0060.02616.09
5.4.200.0070.03815.96
5.4.190.0020.04015.93
5.4.180.0100.03316.04
5.4.170.0030.02916.03
5.4.160.0070.03515.91
5.4.150.0110.03516.04
5.4.140.0050.02814.79
5.4.130.0020.04114.61
5.4.120.0030.04214.71
5.4.110.0050.02414.69
5.4.100.0020.03014.78
5.4.90.0050.03814.54
5.4.80.0020.04414.74
5.4.70.0030.03514.67
5.4.60.0030.04014.75
5.4.50.0060.03814.63
5.4.40.0060.02214.79
5.4.30.0080.03814.74
5.4.20.0110.03214.66
5.4.10.0030.04114.77
5.4.00.0070.03314.55

preferences:
61.99 ms | 401 KiB | 5 Q