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 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.70.0150.00618.47
8.3.60.0090.00618.63
8.3.50.0090.01021.26
8.3.40.0100.00718.92
8.3.30.0140.00418.78
8.3.20.0080.00020.34
8.3.10.0040.00423.79
8.3.00.0050.00322.58
8.2.190.0120.00317.00
8.2.180.0110.01118.33
8.2.170.0120.00322.96
8.2.160.0100.00320.52
8.2.150.0040.00424.18
8.2.140.0080.00024.66
8.2.130.0080.00026.16
8.2.120.0090.00017.63
8.2.110.0030.00720.70
8.2.100.0030.00917.63
8.2.90.0040.00419.05
8.2.80.0080.00017.97
8.2.70.0060.00317.62
8.2.60.0050.00318.04
8.2.50.0060.00318.07
8.2.40.0080.00021.14
8.2.30.0050.00319.89
8.2.20.0000.00717.77
8.2.10.0000.00718.12
8.2.00.0040.00418.02
8.1.280.0070.01425.92
8.1.270.0000.00820.37
8.1.260.0080.00026.35
8.1.250.0040.00428.09
8.1.240.0030.00622.27
8.1.230.0090.00317.42
8.1.220.0000.00917.74
8.1.210.0060.00318.77
8.1.200.0030.00617.38
8.1.190.0060.00317.35
8.1.180.0040.00418.10
8.1.170.0040.00418.53
8.1.160.0020.00522.16
8.1.150.0020.00518.85
8.1.140.0090.00017.55
8.1.130.0040.00417.75
8.1.120.0040.00417.42
8.1.110.0040.00417.39
8.1.100.0030.00517.45
8.1.90.0040.00417.46
8.1.80.0080.00017.52
8.1.70.0020.00517.49
8.1.60.0030.00617.73
8.1.50.0080.00017.62
8.1.40.0030.00617.68
8.1.30.0040.00417.62
8.1.20.0040.00417.79
8.1.10.0000.00817.62
8.1.00.0040.00417.62
8.0.300.0060.00318.77
8.0.290.0040.00417.00
8.0.280.0000.00718.41
8.0.270.0030.00317.31
8.0.260.0030.00317.29
8.0.250.0040.00417.05
8.0.240.0030.00317.04
8.0.230.0030.00316.98
8.0.220.0050.00216.97
8.0.210.0030.00516.91
8.0.200.0060.00017.06
8.0.190.0020.00517.05
8.0.180.0000.00716.93
8.0.170.0040.00417.02
8.0.160.0030.00517.00
8.0.150.0040.00416.85
8.0.140.0080.00316.90
8.0.130.0050.00313.39
8.0.120.0050.00316.91
8.0.110.0040.00417.00
8.0.100.0000.00716.90
8.0.90.0000.00716.88
8.0.80.0030.01317.00
8.0.70.0000.00716.86
8.0.60.0050.00316.95
8.0.50.0040.00416.90
8.0.30.0060.01117.22
8.0.20.0050.01717.40
8.0.10.0040.00417.22
8.0.00.0120.00916.77
7.4.330.0000.00515.26
7.4.320.0030.00316.69
7.4.300.0000.00616.63
7.4.290.0000.00716.60
7.4.280.0060.00316.57
7.4.270.0000.00716.72
7.4.260.0050.00216.73
7.4.250.0040.00416.65
7.4.240.0020.00516.68
7.4.230.0000.00716.61
7.4.220.0130.00316.52
7.4.210.0000.01516.80
7.4.200.0000.00816.69
7.4.160.0090.01516.48
7.4.150.0120.00617.40
7.4.140.0100.01217.86
7.4.130.0120.01216.58
7.4.120.0090.01216.53
7.4.110.0100.00616.52
7.4.100.0120.00916.57
7.4.90.0100.00716.71
7.4.80.0090.00919.39
7.4.70.0030.01716.66
7.4.60.0080.01516.52
7.4.50.0030.00616.48
7.4.40.0130.00316.77
7.4.30.0070.01116.67
7.4.00.0080.01014.81
7.3.330.0030.00313.50
7.3.320.0030.00313.33
7.3.310.0000.00716.53
7.3.300.0070.00016.38
7.3.290.0110.00816.46
7.3.280.0100.00816.47
7.3.270.0190.00317.40
7.3.260.0090.00916.67
7.3.250.0090.01016.50
7.3.240.0070.01116.41
7.3.230.0040.01516.64
7.3.210.0120.00816.66
7.3.200.0090.00919.39
7.3.190.0090.00616.48
7.3.180.0130.00316.46
7.3.170.0150.00416.60
7.3.160.0030.01616.63
7.3.120.0030.01014.94
7.3.110.0100.01014.65
7.3.100.0060.01014.76
7.3.90.0070.00714.97
7.3.80.0060.00914.65
7.3.70.0100.00714.79
7.3.60.0030.01014.75
7.3.50.0070.00414.91
7.3.40.0060.00915.02
7.3.30.0100.00714.68
7.3.20.0000.01816.52
7.3.10.0070.01116.56
7.3.00.0090.00716.65
7.2.330.0130.00616.79
7.2.320.0030.02016.77
7.2.310.0100.00716.74
7.2.300.0060.01016.86
7.2.290.0070.01016.84
7.2.250.0100.01315.16
7.2.240.0080.00815.13
7.2.230.0040.01115.00
7.2.220.0040.00815.08
7.2.210.0090.00614.96
7.2.200.0030.00915.05
7.2.190.0110.00415.08
7.2.180.0040.01414.94
7.2.170.0030.01715.11
7.2.130.0130.00616.93
7.2.120.0070.01016.78
7.2.110.0140.00816.78
7.2.100.0110.00616.71
7.2.90.0150.00916.74
7.2.80.0120.00516.73
7.2.70.0050.01116.69
7.2.60.0090.00916.79
7.2.50.0090.00616.87
7.2.40.0150.00316.91
7.2.30.0130.00516.83
7.2.20.0080.01216.71
7.2.10.0070.01216.70
7.2.00.0170.00116.84
7.1.330.0100.00715.66
7.1.320.0070.00315.48
7.1.310.0070.00315.84
7.1.300.0090.00315.78
7.1.290.0070.01115.81
7.1.280.0070.01015.79
7.1.270.0030.01315.79
7.1.260.0070.00715.88
7.1.250.0080.01015.51
7.1.240.0070.00315.79
7.1.230.0030.00615.83
7.1.220.0060.00315.73
7.1.210.0040.01015.90
7.1.200.0060.00315.75
7.1.190.0000.01115.68
7.1.180.0120.00015.75
7.1.170.0040.00715.58
7.1.160.0060.00615.47
7.1.150.0100.00015.69
7.1.140.0080.00315.86
7.1.130.0040.00715.57
7.1.120.0090.00615.70
7.1.110.0060.00915.87
7.1.100.0030.01015.47
7.1.90.0040.00815.51
7.1.80.0030.01015.50
7.1.70.0030.00616.22
7.1.60.0120.00717.88
7.1.50.0050.01416.24
7.1.40.0060.00315.68
7.1.30.0110.00015.63
7.1.20.0120.00415.69
7.1.10.0070.00715.70
7.1.00.0090.03819.07
7.0.330.0000.01115.51
7.0.320.0000.00715.41
7.0.310.0030.00615.44
7.0.300.0070.00715.17
7.0.290.0140.00015.34
7.0.280.0100.00315.40
7.0.270.0130.00015.36
7.0.260.0070.00715.32
7.0.250.0040.00815.41
7.0.240.0000.01115.48
7.0.230.0080.00415.46
7.0.220.0000.00815.53
7.0.210.0030.00515.57
7.0.200.0120.00416.07
7.0.190.0040.00715.59
7.0.180.0000.01215.35
7.0.170.0070.00415.21
7.0.160.0000.01315.25
7.0.150.0070.00715.27
7.0.140.0030.00615.36
7.0.130.0030.00715.44
7.0.120.0030.00715.26
7.0.110.0090.03817.67
7.0.100.0050.03217.71
7.0.90.0130.05317.65
7.0.80.0030.03317.74
7.0.70.0080.04117.77
7.0.60.0050.02817.83
7.0.50.0060.04117.89
7.0.40.0070.04616.75
7.0.30.0150.03516.84
7.0.20.0110.04016.76
7.0.10.0100.02516.79
7.0.00.0080.04416.62
5.6.380.0040.01214.20
5.6.370.0090.00014.29
5.6.360.0060.00913.98
5.6.350.0050.00514.34
5.6.340.0040.00714.40
5.6.330.0070.00714.23
5.6.320.0090.00014.43
5.6.310.0040.00414.44
5.6.300.0100.00314.63
5.6.290.0040.01114.62
5.6.280.0030.02217.63
5.6.270.0050.00814.71
5.6.260.0060.00614.02
5.6.250.0050.04717.58
5.6.240.0050.04617.45
5.6.230.0060.04917.61
5.6.220.0110.03817.47
5.6.210.0030.04817.46
5.6.200.0150.03517.79
5.6.190.0070.03217.75
5.6.180.0120.04017.57
5.6.170.0050.02317.61
5.6.160.0050.04817.86
5.6.150.0090.04417.67
5.6.140.0080.04217.82
5.6.130.0080.04117.87
5.6.120.0050.04217.78
5.6.110.0130.04917.56
5.6.100.0030.02617.55
5.6.90.0130.03617.57
5.6.80.0080.02917.57
5.6.70.0050.04617.39
5.6.60.0090.02517.37
5.6.50.0040.04217.46
5.6.40.0070.04117.29
5.6.30.0080.04517.38
5.6.20.0000.04917.40
5.6.10.0050.04817.42
5.6.00.0090.04517.29
5.5.380.0030.04515.98
5.5.370.0060.04215.76
5.5.360.0070.03815.70
5.5.350.0080.03515.86
5.5.340.0100.04015.93
5.5.330.0050.04016.14
5.5.320.0150.02616.18
5.5.310.0140.03216.00
5.5.300.0080.02516.23
5.5.290.0020.03215.95
5.5.280.0050.04216.04
5.5.270.0090.02515.89
5.5.260.0050.04716.01
5.5.250.0050.04215.88
5.5.240.0070.04015.77
5.5.230.0100.03315.58
5.5.220.0070.04515.46
5.5.210.0070.04015.65
5.5.200.0050.04515.60
5.5.190.0090.04015.70
5.5.180.0050.02515.81
5.5.170.0050.00311.27
5.5.160.0100.03815.60
5.5.150.0030.04315.75
5.5.140.0070.04115.60
5.5.130.0040.02415.74
5.5.120.0070.03815.59
5.5.110.0050.02515.61
5.5.100.0020.02315.51
5.5.90.0020.02615.59
5.5.80.0050.02315.48
5.5.70.0050.02515.59
5.5.60.0050.03315.52
5.5.50.0080.02315.66
5.5.40.0040.02015.49
5.5.30.0060.02015.58
5.5.20.0060.02115.75
5.5.10.0040.02415.52
5.5.00.0060.03015.47
5.4.450.0080.03815.22
5.4.440.0070.03815.33
5.4.430.0060.04115.38
5.4.420.0050.03815.22
5.4.410.0100.02215.19
5.4.400.0030.04415.02
5.4.390.0060.04115.15
5.4.380.0100.03214.96
5.4.370.0020.04215.11
5.4.360.0050.03715.04
5.4.350.0030.02715.06
5.4.340.0070.03515.03
5.4.330.0060.00610.93
5.4.320.0100.03214.91
5.4.310.0000.03015.08
5.4.300.0050.04115.15
5.4.290.0060.04115.16
5.4.280.0030.02715.01
5.4.270.0060.03215.06
5.4.260.0030.02815.11
5.4.250.0070.02015.17
5.4.240.0020.02215.04
5.4.230.0030.02115.01
5.4.220.0070.02314.95
5.4.210.0050.02514.97
5.4.200.0020.02415.03
5.4.190.0030.02414.92
5.4.180.0000.02415.23
5.4.170.0050.02014.95
5.4.160.0090.01515.06
5.4.150.0020.02415.08
5.4.140.0060.02413.76
5.4.130.0040.02213.90
5.4.120.0100.03313.80
5.4.110.0070.03813.64
5.4.100.0050.04013.75
5.4.90.0030.04013.82
5.4.80.0100.03313.70
5.4.70.0040.04113.77
5.4.60.0050.04113.86
5.4.50.0060.03613.72
5.4.40.0030.03413.70
5.4.30.0080.03713.65
5.4.20.0020.02213.77
5.4.10.0090.03213.64
5.4.00.0050.01913.53

preferences:
48.89 ms | 401 KiB | 5 Q