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; } } protected function getType() { return $this->type; } protected function setType($type) { if (is_numeric($type) && in_array(intval($type), array(0, 1, 2))) { $this->type = intval($type); } else { $this->type = 0; } } protected function getValue() { return $this->value; } protected function getFirstPay() { return $this->first_pay; } protected function setFirstPay($amount) { if (is_numeric($amount)) { $this->first_pay = round(floatval($value), 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 getTotalPrice() { $cost = 0; foreach ($this->shopping_list as $item) { $cost += $item->getCost(); } return $cost; } }

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.0150.00318.43
8.3.50.0160.00621.13
8.3.40.0120.00418.71
8.3.30.0070.00718.73
8.3.20.0040.01120.34
8.3.10.0050.00323.48
8.3.00.0080.00022.34
8.2.180.0040.01818.32
8.2.170.0120.00322.96
8.2.160.0130.00320.33
8.2.150.0000.00824.18
8.2.140.0050.00324.66
8.2.130.0040.00426.16
8.2.120.0040.00417.50
8.2.110.0070.00320.35
8.2.100.0060.00617.78
8.2.90.0030.00518.92
8.2.80.0040.00417.97
8.2.70.0090.00017.36
8.2.60.0040.00717.80
8.2.50.0030.00618.07
8.2.40.0080.00021.04
8.2.30.0000.00819.60
8.2.20.0040.00417.66
8.2.10.0000.00817.83
8.2.00.0000.00817.97
8.1.280.0090.01225.92
8.1.270.0060.00320.03
8.1.260.0000.00826.35
8.1.250.0000.00828.09
8.1.240.0070.00322.00
8.1.230.0000.01123.88
8.1.220.0040.00417.74
8.1.210.0030.00518.77
8.1.200.0060.00317.23
8.1.190.0040.00417.00
8.1.180.0000.00918.10
8.1.170.0040.00418.46
8.1.160.0000.01122.03
8.1.150.0000.00818.84
8.1.140.0050.00317.39
8.1.130.0000.00817.51
8.1.120.0040.00417.36
8.1.110.0040.00417.26
8.1.100.0030.00517.33
8.1.90.0060.00317.34
8.1.80.0000.00817.24
8.1.70.0050.00217.34
8.1.60.0000.00817.51
8.1.50.0000.00817.31
8.1.40.0000.00817.42
8.1.30.0080.00017.45
8.1.20.0080.00017.57
8.1.10.0000.00717.43
8.1.00.0100.00017.21
8.0.300.0040.00418.77
8.0.290.0050.00316.58
8.0.280.0070.00018.36
8.0.270.0040.00417.18
8.0.260.0030.00317.18
8.0.250.0000.00816.74
8.0.240.0040.00416.81
8.0.230.0070.00016.79
8.0.220.0000.00716.77
8.0.210.0070.00016.70
8.0.200.0040.00416.88
8.0.190.0070.00016.84
8.0.180.0070.00016.85
8.0.170.0060.00316.71
8.0.160.0000.00716.85
8.0.150.0070.00016.67
8.0.140.0040.00716.66
8.0.130.0030.00313.18
8.0.120.0040.00416.75
8.0.110.0080.00016.83
8.0.100.0040.00416.86
8.0.90.0000.00816.84
8.0.80.0030.01216.73
8.0.70.0000.00716.65
8.0.60.0000.00716.93
8.0.50.0050.00216.68
8.0.30.0120.00316.96
8.0.20.0100.00917.40
8.0.10.0040.00316.99
8.0.00.0090.00916.61
7.4.330.0050.00015.08
7.4.320.0000.00716.52
7.4.300.0040.00416.44
7.4.290.0030.00316.57
7.4.280.0050.00216.45
7.4.270.0030.00316.35
7.4.260.0080.00016.27
7.4.250.0040.00416.50
7.4.240.0000.00716.51
7.4.230.0030.00316.39
7.4.220.0100.01016.57
7.4.210.0060.01316.52
7.4.200.0000.00716.32
7.4.160.0150.00616.33
7.4.150.0030.01417.40
7.4.140.0150.00717.86
7.4.130.0080.01016.34
7.4.120.0070.01316.51
7.4.110.0060.01716.41
7.4.100.0080.01616.43
7.4.90.0110.00816.36
7.4.80.0100.01019.39
7.4.70.0150.00016.24
7.4.60.0100.00716.29
7.4.50.0050.00316.09
7.4.40.0090.00616.49
7.4.30.0150.00816.45
7.4.00.0040.01114.88
7.3.330.0000.00613.07
7.3.320.0000.00513.14
7.3.310.0040.00416.21
7.3.300.0070.00016.18
7.3.290.0080.00816.22
7.3.280.0070.00916.22
7.3.270.0120.00617.40
7.3.260.0100.00716.55
7.3.250.0120.00616.28
7.3.240.0060.01216.18
7.3.230.0120.00616.54
7.3.210.0090.00916.22
7.3.200.0120.00819.39
7.3.190.0170.00316.23
7.3.180.0030.01316.46
7.3.170.0120.01216.28
7.3.160.0100.00716.22
7.3.00.0070.00916.23
7.2.330.0160.00816.41
7.2.320.0170.00916.61
7.2.310.0160.00316.36
7.2.300.0100.00716.28
7.2.290.0130.00416.57
7.2.130.0100.00716.55
7.2.120.0060.01216.28
7.2.110.0090.00916.45
7.2.100.0110.00316.55
7.2.90.0060.01116.50
7.2.80.0130.00316.56
7.2.70.0030.01116.59
7.2.60.0080.00516.54
7.2.50.0090.00816.62
7.2.40.0080.00416.31
7.2.30.0110.00316.48
7.2.20.0080.00916.54
7.2.10.0100.00516.38
7.2.00.0080.00817.69
7.1.250.0060.01115.38
7.1.240.0050.01015.33
7.1.230.0100.00715.39
7.1.220.0100.00515.46
7.1.210.0070.01015.35
7.1.200.0110.00515.43
7.1.190.0110.00715.32
7.1.180.0100.00515.52
7.1.170.0020.01215.21
7.1.160.0070.00815.51
7.1.150.0090.00915.65
7.1.140.0090.00515.53
7.1.130.0070.00515.55
7.1.120.0100.00315.33
7.1.110.0050.00615.70
7.1.100.0050.00816.05
7.1.90.0080.00615.38
7.1.80.0050.00815.61
7.1.70.0060.00715.91
7.1.60.0080.01116.98
7.1.50.0100.01121.67
7.1.40.0100.00515.56
7.1.30.0100.00615.46
7.1.20.0100.00315.66
7.1.10.0110.00515.57
7.1.00.0050.03117.69
7.0.330.0130.00315.07
7.0.320.0070.00614.91
7.0.310.0060.00514.93
7.0.300.0070.00815.08
7.0.290.0080.00515.07
7.0.280.0070.00715.15
7.0.270.0040.00515.15
7.0.260.0110.00214.92
7.0.250.0030.00815.18
7.0.240.0120.00214.97
7.0.230.0070.00415.16
7.0.220.0040.01015.21
7.0.210.0080.00415.16
7.0.200.0070.00515.73
7.0.190.0070.00715.05
7.0.180.0010.01015.13
7.0.170.0060.01015.26
7.0.160.0090.00715.16
7.0.150.0110.00315.18
7.0.140.0090.00315.10
7.0.130.0080.00614.91
7.0.120.0080.00514.88
7.0.110.0060.00815.06
7.0.100.0070.00615.14
7.0.90.0070.00815.14
7.0.80.0110.00515.16
7.0.70.0070.00715.13
7.0.60.0060.02416.80
7.0.50.0070.01616.04
7.0.40.0120.02515.38
7.0.30.0120.02015.49
7.0.20.0060.01915.45
7.0.10.0030.02115.55
7.0.00.0050.02315.56
5.6.380.0020.01314.27
5.6.370.0040.00714.11
5.6.360.0050.00714.17
5.6.350.0060.00614.10
5.6.340.0100.00514.17
5.6.330.0080.00313.86
5.6.320.0050.00514.19
5.6.310.0090.00314.07
5.6.300.0110.00214.02
5.6.290.0020.01214.18
5.6.280.0110.01916.36
5.6.270.0050.00714.23
5.6.260.0060.00814.18
5.6.250.0020.01313.96
5.6.240.0050.00713.83
5.6.230.0030.00614.04
5.6.220.0050.00714.02
5.6.210.0100.02916.10
5.6.200.0060.02815.44
5.6.190.0090.03116.27
5.6.180.0140.03216.20
5.6.170.0120.03016.13
5.6.160.0110.01816.07
5.6.150.0070.02415.32
5.6.140.0090.03215.52
5.6.130.0030.02015.43
5.6.120.0030.02116.39
5.6.110.0080.02916.36
5.6.100.0100.02716.46
5.6.90.0100.02416.42
5.6.80.0080.03216.04
5.6.70.0680.02116.25
5.6.60.0120.00413.90
5.6.50.0060.01013.97
5.6.40.0000.01513.86
5.6.30.0060.00813.86
5.6.20.0100.00713.83
5.6.10.0080.01013.92
5.6.00.0090.00513.90
5.5.380.0020.00711.04
5.5.370.0050.00711.11
5.5.360.0050.00511.04
5.5.350.0070.02914.15
5.5.340.0060.02913.36
5.5.330.0040.03414.17
5.5.320.0060.01914.13
5.5.310.0110.03214.14
5.5.300.0030.03413.38
5.5.290.0050.01913.36
5.5.280.0050.03014.29
5.5.270.0030.03014.29
5.5.260.0060.02414.33
5.5.250.0050.01814.20
5.5.240.0090.02414.12
5.5.230.0040.00611.04
5.5.220.0050.00611.04
5.5.210.0000.01011.04
5.5.200.0030.00711.04
5.5.190.0070.00411.04
5.5.180.0020.00811.04
5.5.170.0050.00511.04
5.5.160.0070.00411.04
5.5.150.0020.00711.04
5.5.140.0000.00811.04
5.5.130.0060.00411.04
5.5.120.0030.00511.04
5.5.110.0020.00611.04
5.5.100.0040.00811.04
5.5.90.0020.00511.04
5.5.80.0030.00811.04
5.5.70.0050.00511.04
5.5.60.0070.00311.04
5.5.50.0030.00711.04
5.5.40.0050.00311.04
5.5.30.0050.00411.04
5.5.20.0050.00511.04
5.5.10.0080.00211.04
5.5.00.0020.00711.04
5.4.450.0280.02213.94
5.4.440.0340.02313.95
5.4.430.0370.02113.93
5.4.420.0350.02013.74
5.4.410.0340.02313.84
5.4.400.0350.01813.73
5.4.390.0340.02113.71
5.4.380.0330.02113.77
5.4.370.0360.02113.79
5.4.360.0460.02813.65
5.4.350.0430.02013.68
5.4.340.0310.02513.65
5.4.330.0020.00911.04
5.4.320.0390.02113.77
5.4.310.0360.02413.81
5.4.300.0360.01813.79
5.4.290.0330.01613.79
5.4.280.0360.01913.78
5.4.270.0270.02713.77
5.4.260.0340.01613.77
5.4.250.0330.02713.74
5.4.240.0280.02413.73
5.4.230.0300.01813.73
5.4.220.0430.01913.71
5.4.210.0300.02813.68
5.4.200.0320.01812.99
5.4.190.0310.02213.78
5.4.180.0210.02113.70
5.4.170.0220.02813.67
5.4.160.0130.02313.81
5.4.150.0240.01913.70
5.4.140.0170.02212.84
5.4.130.0310.02112.82
5.4.120.0330.02212.86
5.4.110.0370.01612.84
5.4.100.0300.02312.98
5.4.90.0320.02212.97
5.4.80.0320.02412.81
5.4.70.0310.02112.84
5.4.60.0130.01712.88
5.4.50.0050.02312.85
5.4.40.0130.01512.84
5.4.30.0180.02412.75
5.4.20.0150.02512.84
5.4.10.0100.00411.04
5.4.00.0040.00611.04

preferences:
58.37 ms | 401 KiB | 5 Q