3v4l.org

run code in 300+ PHP versions simultaneously
<?php interface RechnungInterface { /** * @param \Discount $discount * @return void */ public function applyDiscount(\Discount $discount); /** * @param \Product $product * @return void */ public function addProduct(\Product $product); /** * @return float */ public function getPrice(); } interface DiscountInterface { /** * @param string $name * @param mixed $value */ public function addCondition($name, $value); /** * @param float $precentage */ public function setDiscount($precentage); /** * @param \Product $product * @return float The new price which should be applied within the \Rechnung */ public function getPrice(\Product $product); } class Dsicount implements DiscountInterface { /** * A list of \Condition * @var array[\Condition] */ private $conditions = []; /** * The discount given on a product which matches the conditions * @var float */ private $discount; /** * @var string */ public $name = ""; /** * {@inheritDoc} */ public function getPrice(\Product $product) { $disc = false; foreach($this->conditions as $cond) { $disc = ($cond[1] == $product->{$cond[0]}); if(!$disc) { return $product->price; } } return $product->price * (1 + $this->discount); } /** * {@inheritDoc} */ public function addCondition($name, $value) { $arr = [$name, $value]; $this->conditions[] = $arr; } /** * {@inheritDoc} */ public function setDiscount($discount) { $this->discount = $discount; } public function __construct($name) { $this->name = $name; } } class Product { /** * @var float */ public $price = 0; /** * @var string */ public $name = ""; /** * @var integer */ public $count = 1; /** * @param string * @param float */ public function __construct($name, $price) { $this->name = $name; $this->price = $price; } } class Rechnung implements RechnungInterface { /** * A list of applied \Discount * @var array[\Discount] */ private $discounts = []; /** * A list of \Product on this sheet * @var array[\Product] */ private $products = []; /** * @param string $name */ public function __construct($name) { $this->subject = $name; } /** * {@inheritDoc} */ public function addProduct(\Product $product) { if(!isset($this->products[$product->name])) { $this->products[$product->name] = $product; } } /** * {@inheritDoc} */ public function applyDiscount(\Discount $discount) { if(!isset($this->discounts[$discount->name])) { $this->discounts[$discount->name] = $discount; } } /** * {@inheritDoc} */ public function getPrice() { $total = 0; foreach($this->products as $product) { foreach($this->discounts as $discount) { $product->price = $discount->getPrice($product); } $total += $product->price; } return $total; } } $rechnung = new Rechnung("AJ"); $produkt = new Product("Auto", 800); $rechnung->addProduct($produkt); var_dump($rechnung); $rabatt = new Discount("name", "Auto"); $rechnung->applyDiscount($rabatt); echo $rechnung->getPrice(); var_dump($rechnung);

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.0140.00716.75
8.3.50.0060.00918.07
8.3.40.0120.00318.85
8.3.30.0070.00718.79
8.3.20.0040.00420.16
8.3.10.0000.00823.66
8.3.00.0000.00919.97
8.2.180.0070.01018.54
8.2.170.0120.00322.96
8.2.160.0070.00720.47
8.2.150.0080.00024.18
8.2.140.0080.00024.66
8.2.130.0080.00019.21
8.2.120.0080.00026.35
8.2.110.0080.00020.43
8.2.100.0080.00417.93
8.2.90.0000.00819.30
8.2.80.0040.00417.97
8.2.70.0030.00617.88
8.2.60.0090.00017.93
8.2.50.0000.00818.07
8.2.40.0030.00620.19
8.2.30.0040.00420.55
8.2.20.0040.00417.97
8.2.10.0050.00318.09
8.2.00.0040.00418.28
8.1.280.0170.00325.92
8.1.270.0050.00320.33
8.1.260.0080.00028.09
8.1.250.0040.00428.09
8.1.240.0060.00323.86
8.1.230.0060.00617.66
8.1.220.0000.00817.74
8.1.210.0080.00018.77
8.1.200.0060.00317.48
8.1.190.0000.00817.35
8.1.180.0050.00318.10
8.1.170.0040.00418.53
8.1.160.0000.00720.77
8.1.150.0000.00718.84
8.1.140.0000.00819.52
8.1.130.0000.00717.71
8.1.120.0070.00017.45
8.1.110.0030.00517.43
8.1.100.0000.00717.56
8.1.90.0000.00717.46
8.1.80.0040.00417.40
8.1.70.0040.00417.38
8.1.60.0000.00817.62
8.1.50.0000.00817.50
8.1.40.0000.00817.57
8.1.30.0000.00817.54
8.1.20.0040.00417.62
8.1.10.0000.00817.60
8.1.00.0000.00817.55
8.0.300.0030.00518.77
8.0.290.0040.00416.88
8.0.280.0070.00018.45
8.0.270.0000.00717.18
8.0.260.0000.00617.16
8.0.250.0000.00717.09
8.0.240.0040.00417.07
8.0.230.0040.00417.04
8.0.220.0080.00017.00
8.0.210.0040.00417.00
8.0.200.0030.00317.05
8.0.190.0080.00016.96
8.0.180.0030.00617.02
8.0.170.0080.00017.02
8.0.160.0040.00416.91
8.0.150.0040.00416.98
8.0.140.0000.00716.93
8.0.130.0070.00013.39
8.0.120.0040.00416.96
8.0.110.0040.00416.94
8.0.100.0050.00217.02
8.0.90.0000.00817.10
8.0.80.0130.00917.05
8.0.70.0000.00716.89
8.0.60.0040.00417.01
8.0.50.0080.00016.87
8.0.30.0120.00817.12
8.0.20.0080.01117.40
8.0.10.0040.00416.99
8.0.00.0110.00917.00
7.4.330.0030.00316.73
7.4.320.0000.00816.56
7.4.300.0030.00316.55
7.4.290.0060.00316.45
7.4.280.0040.00416.64
7.4.270.0030.00416.56
7.4.260.0080.00016.56
7.4.250.0080.00016.59
7.4.240.0020.00616.58
7.4.230.0030.00316.76
7.4.220.0060.01616.59
7.4.210.0060.00916.72
7.4.200.0030.00316.62
7.4.160.0110.00716.57
7.4.150.0130.00617.40
7.4.140.0110.01117.86
7.4.130.0060.01316.49
7.4.120.0090.01116.60
7.4.110.0150.00316.47
7.4.100.0060.01216.61
7.4.90.0090.01016.76
7.4.80.0090.00919.39
7.4.70.0100.00716.61
7.4.60.0060.00916.44
7.4.50.0060.00916.43
7.4.40.0150.00316.55
7.4.30.0120.00616.57
7.4.10.0070.01015.11
7.4.00.0060.01214.97
7.3.330.0030.00313.33
7.3.320.0030.00313.36
7.3.310.0000.00716.53
7.3.300.0050.00316.41
7.3.290.0080.00916.50
7.3.280.0040.01016.51
7.3.270.0090.00917.40
7.3.260.0110.00816.48
7.3.240.0060.01216.65
7.3.230.0090.00916.62
7.3.210.0140.00716.51
7.3.200.0100.00716.38
7.3.190.0060.01216.40
7.3.180.0070.01016.59
7.3.170.0140.00416.47
7.3.160.0140.00316.79
7.3.130.0070.01115.20
7.3.120.0070.01015.14
7.3.110.0110.00714.83
7.3.100.0070.00714.91
7.3.90.0000.01215.25
7.3.80.0070.00315.00
7.3.70.0140.00015.00
7.3.60.0070.01014.96
7.3.50.0070.00714.93
7.3.40.0000.00814.61
7.3.30.0050.00515.02
7.3.20.0120.00616.55
7.3.10.0020.01116.65
7.3.00.0070.00716.52
7.2.330.0090.00916.91
7.2.320.0060.01316.80
7.2.310.0100.00716.49
7.2.300.0100.01316.84
7.2.290.0180.00316.67
7.2.260.0060.01315.13
7.2.250.0080.01214.71
7.2.240.0100.00715.07
7.2.230.0100.00714.89
7.2.220.0060.00915.30
7.2.210.0090.00615.35
7.2.200.0030.00915.29
7.2.190.0070.01014.90
7.2.180.0070.01015.01
7.2.170.0030.01015.05
7.2.160.0030.00914.96
7.2.150.0090.00616.97
7.2.140.0070.01316.73
7.2.130.0070.00716.95
7.2.120.0050.01016.97
7.2.110.0060.00716.90
7.2.100.0060.01216.86
7.2.90.0100.00616.93
7.2.80.0060.00716.98
7.2.70.0080.00816.73
7.2.60.0120.01116.78
7.2.50.0070.00817.01
7.2.40.0020.01316.86
7.2.30.0050.00816.97
7.2.20.0060.01016.82
7.2.10.0070.00717.06
7.2.00.0060.00617.78
7.1.330.0040.01115.91
7.1.320.0100.00315.84
7.1.310.0060.00815.74
7.1.300.0080.00815.79
7.1.290.0000.01015.70
7.1.280.0070.00715.73
7.1.270.0090.00015.86
7.1.260.0080.01115.73
7.1.250.0090.00415.82
7.1.240.0040.00715.80
7.1.230.0060.00815.65
7.1.220.0030.00615.68
7.1.210.0120.00415.65
7.1.200.0040.00715.97
7.1.190.0120.00015.83
7.1.180.0070.00715.55
7.1.170.0000.01115.54
7.1.160.0030.01215.54
7.1.150.0090.00315.94
7.1.140.0040.01115.86
7.1.130.0070.00716.02
7.1.120.0000.01315.55
7.1.110.0000.01315.86
7.1.100.0080.00617.03
7.1.90.0030.01015.79
7.1.80.0060.00315.91
7.1.70.0030.01216.32
7.1.60.0050.01417.53
7.1.50.0060.00616.32
7.1.40.0040.01115.89
7.1.30.0030.01015.86
7.1.20.0030.01015.79
7.1.10.0080.00015.92
7.1.00.0070.03618.93
7.0.330.0060.00615.48
7.0.320.0060.00615.17
7.0.310.0030.00915.43
7.0.300.0060.00615.37
7.0.290.0070.00315.45
7.0.280.0000.00815.64
7.0.270.0030.00615.57
7.0.260.0060.00615.13
7.0.250.0110.00415.62
7.0.240.0070.00715.23
7.0.230.0030.01215.48
7.0.220.0040.00815.33
7.0.210.0000.01115.57
7.0.200.0040.00716.21
7.0.190.0070.00715.55
7.0.180.0040.01115.18
7.0.170.0060.00615.09
7.0.160.0040.00715.52
7.0.150.0000.00815.48
7.0.140.0060.00615.40
7.0.130.0030.00915.52
7.0.120.0050.00815.55
7.0.110.0030.01015.57
7.0.100.0030.00915.48
7.0.90.0100.00015.34
7.0.80.0000.01515.43
7.0.70.0120.00315.57
7.0.60.0100.04017.73
7.0.50.0030.04516.75
7.0.40.0040.03016.76
7.0.30.0120.02916.86
7.0.20.0190.04216.79
7.0.10.0070.03816.87
7.0.00.0020.04716.81
5.6.400.0060.00314.56
5.6.390.0070.00714.59
5.6.380.0000.01214.18
5.6.370.0080.00314.66
5.6.360.0070.00714.48
5.6.350.0070.00714.48
5.6.340.0070.00714.46
5.6.330.0080.00414.71
5.6.320.0070.00714.84
5.6.310.0000.01514.54
5.6.300.0100.00314.49
5.6.290.0040.01114.36
5.6.280.0070.01617.88
5.6.270.0070.00714.73
5.6.260.0030.00614.59
5.6.250.0060.00814.56
5.6.240.0030.01214.54
5.6.230.0070.00714.48
5.6.220.0060.00314.65
5.6.210.0090.03617.45
5.6.200.0070.02016.27
5.6.190.0060.03217.53
5.6.180.0150.02717.38
5.6.170.0080.02817.56
5.6.160.0040.05117.56
5.6.150.0070.02916.32
5.6.140.0020.05016.38
5.6.130.0060.03116.16
5.6.120.0020.02917.71
5.6.110.0120.04017.79
5.6.100.0090.04517.86
5.6.90.0140.03717.78
5.6.80.0060.04017.45
5.6.70.0030.01314.45
5.6.60.0100.00614.71
5.6.50.0040.01114.59
5.6.40.0090.00614.56
5.6.30.0030.00614.65
5.6.20.0040.01114.59
5.6.10.0060.00614.32
5.6.00.0030.00614.58
5.5.380.0060.00914.34
5.5.370.0090.00914.79
5.5.360.0000.01314.66
5.5.350.0070.04317.47
5.5.340.0060.02516.17
5.5.330.0050.04817.53
5.5.320.0270.04317.29
5.5.310.0170.03517.46
5.5.300.0080.04516.21
5.5.290.0070.04416.20
5.5.280.0100.03017.69
5.5.270.0030.03217.67
5.5.260.0060.04517.48
5.5.250.0050.02117.52
5.5.240.1590.02617.39
5.5.230.0000.01114.21
5.5.220.0070.00714.40
5.5.210.0060.00914.48
5.5.200.0000.01514.34
5.5.190.0030.01014.29
5.5.180.0040.01114.39
5.5.170.0060.01114.28
5.5.160.0000.00814.34
5.5.150.0100.00714.50
5.5.140.0110.00314.21
5.5.130.0070.01014.23
5.5.120.0000.01514.51
5.5.110.0040.01514.64
5.5.100.0110.00714.61
5.5.90.0070.01114.40
5.5.80.0060.00314.67
5.5.70.0040.00814.38
5.5.60.0130.00314.11
5.5.50.0030.01314.39
5.5.40.0060.00914.29
5.5.30.0030.01313.95
5.5.20.0040.01214.04
5.5.10.0070.01014.09
5.5.00.0110.00614.19

preferences:
39.72 ms | 400 KiB | 5 Q