3v4l.org

run code in 300+ PHP versions simultaneously
<?php // A basic shopping cart which contains a list of added products // and the quantity of each product. Includes a method which // calculates the total price of the items in the cart using a // closure as a callback. class Cart { const PRICE_BUTTER = 1.00; const PRICE_MILK = 3.00; const PRICE_EGGS = 6.95; protected $products = array(); public function add($product, $quantity) { $this->products[$product] = $quantity; } public function getQuantity($product) { return isset($this->products[$product]) ? $this->products[$product] : FALSE; } public function getTotal($tax) { $total = 0.00; $callback = function ($quantity, $product) use ($tax, &$total) { $pricePerItem = constant(__CLASS__ . "::PRICE_" . strtoupper($product)); $total += ($pricePerItem * $quantity) * ($tax + 1.0); }; array_walk($this->products, $callback); return round($total, 2); } } $my_cart = new Cart; // Add some items to the cart $my_cart->add('butter', 1); $my_cart->add('milk', 3); $my_cart->add('eggs', 6); // Print the total with a 5% sales tax. print $my_cart->getTotal(0.05) . "\n"; // The result is 54.29

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.40.0060.00918.65
8.3.30.0070.00719.34
8.3.20.0050.00320.38
8.3.10.0030.00523.79
8.3.00.0090.00020.93
8.2.170.0140.00022.96
8.2.160.0070.00720.52
8.2.150.0030.00524.18
8.2.140.0000.00824.66
8.2.130.0040.00426.16
8.2.120.0090.00022.39
8.2.110.0090.00019.24
8.2.100.0060.00617.91
8.2.90.0080.00017.89
8.2.80.0080.00017.97
8.2.70.0000.00817.75
8.2.60.0040.00418.16
8.2.50.0000.01118.07
8.2.40.0000.00918.16
8.2.30.0050.00318.09
8.2.20.0000.00917.76
8.2.10.0000.00817.75
8.2.00.0060.00317.82
8.1.270.0030.00623.84
8.1.260.0050.00326.35
8.1.250.0040.00428.09
8.1.240.0080.00022.73
8.1.230.0070.00422.75
8.1.220.0040.00417.76
8.1.210.0030.00618.95
8.1.200.0040.00417.48
8.1.190.0040.00417.35
8.1.180.0000.00818.10
8.1.170.0060.00318.67
8.1.160.0000.00718.98
8.1.150.0000.00818.68
8.1.140.0040.00417.41
8.1.130.0030.00317.82
8.1.120.0070.00017.61
8.1.110.0000.00717.55
8.1.100.0030.00617.44
8.1.90.0000.00717.45
8.1.80.0000.00717.47
8.1.70.0030.00317.42
8.1.60.0040.00417.64
8.1.50.0040.00417.51
8.1.40.0050.00317.59
8.1.30.0000.00917.64
8.1.20.0050.00317.77
8.1.10.0040.00417.65
8.1.00.0080.00317.53
8.0.300.0000.00720.02
8.0.290.0040.00416.88
8.0.280.0000.00718.56
8.0.270.0070.00017.40
8.0.260.0060.00016.96
8.0.250.0030.00316.96
8.0.240.0000.00816.93
8.0.230.0080.00016.93
8.0.220.0030.00317.00
8.0.210.0000.00716.94
8.0.200.0030.00317.05
8.0.190.0040.00417.00
8.0.180.0030.00616.97
8.0.170.0000.00817.01
8.0.160.0070.00016.99
8.0.150.0000.00716.96
8.0.140.0000.00816.83
8.0.130.0060.00013.48
8.0.120.0000.00717.01
8.0.110.0080.00017.00
8.0.100.0040.00416.93
8.0.90.0070.00016.94
8.0.80.0120.00316.90
8.0.70.0070.00017.04
8.0.60.0040.00416.85
8.0.50.0080.00016.87
8.0.30.0090.01017.00
8.0.20.0090.00917.40
8.0.10.0050.00217.01
8.0.00.0150.00517.01
7.4.330.0000.00615.14
7.4.320.0060.00016.68
7.4.300.0080.00016.70
7.4.290.0070.00016.70
7.4.280.0030.00516.59
7.4.270.0000.00716.70
7.4.260.0030.00516.61
7.4.250.0030.00316.57
7.4.240.0040.00416.64
7.4.230.0070.00016.65
7.4.220.0070.01116.73
7.4.210.0100.00716.67
7.4.200.0050.00316.79
7.4.190.0070.00016.76
7.4.160.0060.00916.59
7.4.150.0160.00917.40
7.4.140.0130.00417.86
7.4.130.0120.00516.60
7.4.120.0120.00716.74
7.4.110.0070.01016.54
7.4.100.0130.00316.78
7.4.90.0100.00716.66
7.4.80.0060.01119.39
7.4.70.0030.01316.51
7.4.60.0150.00616.64
7.4.50.0030.00316.38
7.4.40.0060.00622.77
7.4.30.0060.00916.67
7.4.10.0060.01215.13
7.4.00.0080.00914.84
7.3.330.0000.00513.46
7.3.320.0050.00013.31
7.3.310.0030.00316.47
7.3.300.0000.00716.40
7.3.290.0090.00616.38
7.3.280.0060.01216.45
7.3.270.0160.00317.40
7.3.260.0100.00716.46
7.3.250.0130.00816.50
7.3.240.0110.00616.50
7.3.230.0100.00716.55
7.3.210.0110.00616.53
7.3.200.0080.00819.39
7.3.190.0110.00616.64
7.3.180.0110.00416.66
7.3.170.0000.01816.39
7.3.160.0080.00816.52
7.3.130.0100.00814.84
7.3.120.0060.01014.89
7.3.110.0080.00914.91
7.3.100.0050.00914.89
7.3.90.0040.01114.99
7.3.80.0040.00914.99
7.3.70.0050.01014.81
7.3.60.0030.00914.89
7.3.50.0070.00514.84
7.3.40.0080.00515.01
7.3.30.0090.00314.84
7.3.20.0070.00916.72
7.3.10.0090.00316.56
7.3.00.0060.01016.48
7.2.330.0060.01116.87
7.2.320.0060.01616.75
7.2.310.0150.00416.70
7.2.300.0030.01316.84
7.2.290.0060.01016.84
7.2.260.0080.01015.02
7.2.250.0090.00915.02
7.2.240.0020.01315.07
7.2.230.0110.00515.14
7.2.220.0080.00615.14
7.2.210.0080.00614.96
7.2.200.0080.00814.93
7.2.190.0020.01215.12
7.2.180.0050.01015.12
7.2.170.0050.01014.94
7.2.160.0030.00815.03
7.2.150.0050.01216.81
7.2.140.0060.00716.93
7.2.130.0060.01016.96
7.2.120.0050.00916.93
7.2.110.0060.00716.91
7.2.100.0080.00816.80
7.2.90.0100.00516.90
7.2.80.0060.00916.97
7.2.70.0100.00516.90
7.2.60.0040.01117.03
7.2.50.0000.01116.91
7.2.40.0060.00717.08
7.2.30.0080.00516.75
7.2.20.0100.00717.00
7.2.10.0080.00316.77
7.2.00.0110.00316.83
7.1.330.0070.00315.76
7.1.320.0060.00715.85
7.1.310.0040.00915.94
7.1.300.0050.00615.86
7.1.290.0060.00515.58
7.1.280.0070.00715.80
7.1.270.0060.00815.89
7.1.260.0110.00315.82
7.1.250.0060.00615.86
7.1.240.0050.00515.92
7.1.230.0080.00415.89
7.1.220.0070.00515.71
7.1.210.0100.00515.93
7.1.200.0060.01015.83
7.1.190.0030.01015.76
7.1.180.0070.00515.77
7.1.170.0030.00915.95
7.1.160.0050.00715.92
7.1.150.0060.00615.65
7.1.140.0090.00215.86
7.1.130.0030.01015.84
7.1.120.0030.00615.72
7.1.110.0060.00615.79
7.1.100.0020.00915.74
7.1.90.0030.00715.67
7.1.80.0030.01115.74
7.1.70.0050.00716.36
7.1.60.0070.01016.91
7.1.50.0060.01016.17
7.1.40.0070.00715.73
7.1.30.0020.01015.66
7.1.20.0020.00915.80
7.1.10.0070.00715.82
7.1.00.0050.03017.90
7.0.330.0020.00815.35
7.0.320.0070.00715.25
7.0.310.0030.01115.48
7.0.300.0040.00815.31
7.0.290.0050.00915.47
7.0.280.0020.01015.29
7.0.270.0070.00715.34
7.0.260.0040.00415.41
7.0.250.0090.00515.28
7.0.240.0030.00615.22
7.0.230.0070.00515.40
7.0.220.0090.00615.49
7.0.210.0040.00915.52
7.0.200.0030.00815.74
7.0.190.0070.00715.47
7.0.180.0050.00615.46
7.0.170.0000.01015.56
7.0.160.0050.00515.35
7.0.150.0050.00815.44
7.0.140.0060.02717.67
7.0.130.0030.00915.40
7.0.120.0040.00715.40
7.0.110.0070.00515.44
7.0.100.0320.02916.99
7.0.90.0200.03016.89
7.0.80.0230.02916.95
7.0.70.0210.03116.89
7.0.60.0130.03116.90
7.0.50.0210.03117.11
7.0.40.0040.03415.68
7.0.30.0040.03515.72
7.0.20.0060.03415.69
7.0.10.0030.03415.71
7.0.00.0040.02815.63
5.6.400.0070.00614.47
5.6.390.0090.00614.29
5.6.380.0070.00614.46
5.6.370.0080.00614.72
5.6.360.0030.00714.60
5.6.350.0030.00914.56
5.6.340.0010.01214.62
5.6.330.0090.00414.56
5.6.320.0020.01114.62
5.6.310.0000.01114.26
5.6.300.0020.01314.36
5.6.290.0070.00714.53
5.6.280.0010.03116.79
5.6.270.0030.00814.41
5.6.260.0040.00614.72
5.6.250.0090.01816.59
5.6.240.0080.03016.39
5.6.230.0100.03116.50
5.6.220.0020.03316.52
5.6.210.0080.02416.52
5.6.200.0080.01516.53
5.6.190.0090.03016.83
5.6.180.0060.03116.79
5.6.170.0020.03216.59
5.6.160.0100.03116.71
5.6.150.0060.03716.65
5.6.140.0080.02816.68
5.6.130.0110.02416.71
5.6.120.0020.03516.70
5.6.110.0030.02916.65
5.6.100.0060.03316.52
5.6.90.0060.03216.54
5.6.80.0040.03316.34
5.6.70.0070.02416.41
5.6.60.0090.02716.42
5.6.50.0060.03116.39
5.6.40.0050.03416.33
5.6.30.0080.02516.44
5.6.20.0080.03016.45
5.6.10.0060.03416.38
5.6.00.0070.02916.56
5.5.380.0070.03316.52
5.5.370.0060.03116.37
5.5.360.0040.02416.39
5.5.350.0040.03316.42
5.5.340.0080.02916.63
5.5.330.0040.03216.57
5.5.320.0020.02616.66
5.5.310.0030.03016.65
5.5.300.0040.03216.62
5.5.290.0000.03416.69
5.5.280.0100.03016.63
5.5.270.0070.03016.40
5.5.260.0070.03316.61
5.5.250.0050.03516.42
5.5.240.0050.03216.42
5.5.230.0050.03516.25
5.5.220.0040.02616.17
5.5.210.0080.01716.22
5.5.200.0080.02516.30
5.5.190.0090.02716.23
5.5.180.0050.02616.14
5.5.170.0030.01014.33
5.5.160.0040.02016.30
5.5.150.0100.02716.44
5.5.140.0060.02216.17
5.5.130.0110.02416.33
5.5.120.0030.02016.21
5.5.110.0080.02616.35
5.5.100.0080.03016.24
5.5.90.0030.03716.14
5.5.80.0050.02916.05
5.5.70.0030.03516.17
5.5.60.0050.03216.37
5.5.50.0070.03116.24
5.5.40.0020.03416.06
5.5.30.0050.02916.25
5.5.20.0070.02816.30
5.5.10.0100.03116.24
5.5.00.0070.03316.11
5.4.450.0070.02813.84
5.4.440.0030.03114.11
5.4.430.0030.02914.00
5.4.420.0060.02913.91
5.4.410.0030.03113.97
5.4.400.0020.03313.83
5.4.390.0060.02713.80
5.4.380.0090.02613.89
5.4.370.0050.03013.77
5.4.360.0050.02413.77
5.4.350.0050.02913.84
5.4.340.0080.02613.84
5.4.330.0030.00711.33
5.4.320.0020.03313.84
5.4.310.0060.02413.90
5.4.300.0050.02713.80
5.4.290.0040.02813.78
5.4.280.0060.02613.89
5.4.270.0050.01713.99
5.4.260.0050.03113.93
5.4.250.0020.02613.79
5.4.240.0070.02913.86
5.4.230.0050.02013.68
5.4.220.0080.02513.82
5.4.210.0040.02913.79
5.4.200.0090.02213.87
5.4.190.0050.03013.76
5.4.180.0080.02413.79
5.4.170.0070.02513.79
5.4.160.0070.02513.81
5.4.150.0040.02613.83
5.4.140.0040.02912.98
5.4.130.0050.02813.00
5.4.120.0000.03412.96
5.4.110.0060.02613.07
5.4.100.0060.02612.96
5.4.90.0030.02713.05
5.4.80.0060.02712.92
5.4.70.0030.02712.87
5.4.60.0050.02912.99
5.4.50.0060.02712.94
5.4.40.0060.02712.91
5.4.30.0070.02512.88
5.4.20.0010.03113.02
5.4.10.0060.02213.00
5.4.00.0060.02612.77
5.3.290.0030.03011.98
5.3.280.0020.03211.85
5.3.270.0050.03112.12
5.3.260.0060.03012.04
5.3.250.0040.02611.94
5.3.240.0090.02311.89
5.3.230.0060.02911.92
5.3.220.0030.02911.96
5.3.210.0050.02611.93
5.3.200.0030.02311.79
5.3.190.0080.02811.92
5.3.180.0030.03011.97
5.3.170.0070.02511.97
5.3.160.0050.02711.98
5.3.150.0020.03211.97
5.3.140.0020.02212.04
5.3.130.0050.02911.88
5.3.120.0050.02212.03
5.3.110.0020.03212.07
5.3.100.0010.02111.77
5.3.90.0060.02511.77
5.3.80.0030.02911.66
5.3.70.0090.02311.79
5.3.60.0090.02411.72
5.3.50.0020.03011.66
5.3.40.0060.02911.79
5.3.30.0060.01811.77
5.3.20.0030.02911.63
5.3.10.0100.02011.43
5.3.00.0040.02611.55
5.2.170.0170.05313.82
5.2.160.0070.06013.82
5.2.150.0070.05313.82
5.2.140.0100.05713.82
5.2.130.0030.06313.82
5.2.120.0070.05713.82
5.2.110.0030.06313.82
5.2.100.0030.06313.82
5.2.90.0100.02713.82
5.2.80.0000.06713.82
5.2.70.0130.04013.82
5.2.60.0070.05713.82
5.2.50.0030.04313.82
5.2.40.0070.05713.82
5.2.30.0100.05713.82
5.2.20.0130.05313.82
5.2.10.0030.06313.82
5.2.00.0070.06013.82
5.1.60.0070.05313.82
5.1.50.0070.05713.82
5.1.40.0030.05713.82
5.1.30.0070.05013.82
5.1.20.0030.04013.82
5.1.10.0030.05713.82
5.1.00.0070.04713.82
5.0.50.0030.05013.82
5.0.40.0070.04313.82
5.0.30.0000.03713.82
5.0.20.0030.04013.82
5.0.10.0070.04013.82
5.0.00.0030.06713.82
4.4.90.0000.03713.82
4.4.80.0030.03713.82
4.4.70.0000.03713.82
4.4.60.0000.04013.82
4.4.50.0000.03713.82
4.4.40.0030.03313.82
4.4.30.0070.03013.82
4.4.20.0030.03313.82
4.4.10.0000.03713.82
4.4.00.0000.05313.82
4.3.110.0030.03013.82
4.3.100.0000.04013.82
4.3.90.0000.04013.82
4.3.80.0000.03713.82
4.3.70.0030.03313.82
4.3.60.0030.03013.82
4.3.50.0000.04013.82
4.3.40.0070.04713.82
4.3.30.0030.03313.82
4.3.20.0000.03713.82
4.3.10.0030.03313.82
4.3.00.0030.02713.82

preferences:
45.25 ms | 400 KiB | 5 Q