3v4l.org

run code in 300+ PHP versions simultaneously
<?php class UnitConverter { public $vulgar_to_float = ['½' => 0.5]; public function replaceUnicode( $amount = 0 ){ $half = $this->vulgar_to_float['½']; return ( is_numeric( $amount ) )? $amount : $half; } public function convertAmount($amount, $from, $to){ if($from === 'pound' && $to === 'ounce'){ return $amount * 16; } else if($from === 'cup' && $to === 'tablespoon'){ return $this->replaceUnicode( $amount ) * 16; } else { throw new Exception('Unable to convert ' . $from . ' to ' . $to); } } } function convertIngredients( $arr = null){ $unit_names = array_column($arr, 'unit_name'); foreach($unit_names as $key => $unit){ if( $unit === 'pound'){ $arr[$key]['amount'] = (new UnitConverter())->convertAmount($arr[$key]['amount'], $unit, 'ounce'); $arr[$key]['unit_name'] = 'ounce'; } else if($unit === 'cup'){ $arr[$key]['amount'] = (new UnitConverter())->convertAmount($arr[$key]['amount'], $unit, 'tablespoon'); $arr[$key]['unit_name'] = 'tablespoon'; } else { continue; } } return $arr; } function generateBreakfast(){ $array = [ 0 => array( 'amount' => 1, 'unit_name' => 'cup', 'ingredient_name' => 'almond flour' ), 1 => array( 'amount' => '½', 'unit_name' => 'cup', 'ingredient_name' => 'erythritol' ), 2 => array( 'amount' => 1, 'unit_name' => 'large', 'ingredient_name' => 'egg' ) ]; return convertIngredients($array); } echo '<pre>'; print_r(generateBreakfast()); echo '</pre>';

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.5.00.0110.01120.20
8.4.150.0020.00014.05
8.4.140.0150.00617.48
8.4.130.0100.01117.49
8.4.120.0050.00424.08
8.4.110.0130.00822.38
8.4.100.0160.00417.86
8.4.90.0110.01020.40
8.4.80.0010.00719.11
8.4.70.0050.00420.74
8.4.60.0110.01220.69
8.4.50.0060.00218.82
8.4.40.0040.01517.61
8.4.30.0000.01017.60
8.4.20.0100.01019.32
8.4.10.0000.00919.59
8.3.280.0130.00718.36
8.3.270.0120.00716.70
8.3.260.0120.00816.60
8.3.250.0090.00818.89
8.3.240.0080.01017.27
8.3.230.0080.01116.44
8.3.220.0140.00620.64
8.3.210.0130.00618.36
8.3.200.0040.00516.83
8.3.190.0090.00816.60
8.3.180.0100.00918.36
8.3.170.0180.00020.65
8.3.160.0190.00020.28
8.3.150.0150.00317.41
8.3.140.0080.00017.30
8.3.130.0040.00418.72
8.3.120.0060.00319.05
8.3.110.0130.00720.94
8.3.100.0080.00018.55
8.3.90.0040.01126.77
8.3.80.0030.00618.30
8.3.70.0140.00416.63
8.3.60.0120.00618.30
8.3.50.0150.00518.13
8.3.40.0120.00318.88
8.3.30.0130.00718.67
8.3.20.0080.00020.16
8.3.10.0000.00823.61
8.3.00.0030.00519.25
8.2.290.0120.00717.25
8.2.280.0150.00418.65
8.2.270.0160.00318.98
8.2.260.0040.00418.61
8.2.250.0000.00818.58
8.2.240.0060.00317.07
8.2.230.0140.00722.58
8.2.220.0040.00424.06
8.2.210.0030.00526.77
8.2.200.0030.00618.16
8.2.190.0160.00316.75
8.2.180.0070.00716.63
8.2.170.0150.00022.96
8.2.160.0070.00719.45
8.2.150.0040.00424.18
8.2.140.0000.00824.66
8.2.130.0050.00226.16
8.2.120.0050.00319.39
8.2.110.0060.00320.13
8.2.100.0110.00617.58
8.2.90.0090.00017.91
8.2.80.0060.00317.97
8.2.70.0000.00817.93
8.2.60.0060.00318.22
8.2.50.0080.00018.10
8.2.40.0040.00419.47
8.2.30.0040.00419.60
8.2.20.0050.00318.22
8.2.10.0040.00418.10
8.2.00.0070.00018.22
8.1.330.0130.00622.09
8.1.320.0080.01017.82
8.1.310.0030.00618.54
8.1.300.0040.01119.99
8.1.290.0030.00630.84
8.1.280.0040.01425.92
8.1.270.0080.00020.25
8.1.260.0040.00426.35
8.1.250.0080.00028.09
8.1.240.0000.00924.02
8.1.230.0040.00820.97
8.1.220.0050.00317.79
8.1.210.0050.00518.77
8.1.200.0050.00517.25
8.1.190.0050.00317.35
8.1.180.0000.00918.10
8.1.170.0050.00318.57
8.1.160.0000.00718.84
8.1.150.0030.00620.21
8.1.140.0070.00017.73
8.1.130.0000.00717.48
8.1.120.0000.00717.47
8.1.110.0000.00817.36
8.1.100.0040.00417.52
8.1.90.0000.00817.34
8.1.80.0000.00817.43
8.1.70.0030.00517.52
8.1.60.0030.00617.62
8.1.50.0040.00417.54
8.1.40.0050.00317.55
8.1.30.0050.00317.58
8.1.20.0050.00317.58
8.1.10.0040.00417.64
8.1.00.0040.00417.45
8.0.300.0070.00021.91
8.0.290.0030.00616.63
8.0.280.0030.00318.41
8.0.270.0030.00618.52
8.0.260.0030.00316.81
8.0.250.0070.00017.02
8.0.240.0000.00816.90
8.0.230.0000.00916.87
8.0.220.0040.00416.86
8.0.210.0070.00016.94
8.0.200.0030.00316.98
8.0.190.0080.00017.01
8.0.180.0040.00416.94
8.0.170.0000.00916.83
8.0.160.0000.00717.00
8.0.150.0030.00616.92
8.0.140.0000.00716.80
8.0.130.0000.00613.41
8.0.120.0080.00016.88
8.0.110.0030.00516.83
8.0.100.0040.00416.80
8.0.90.0000.00716.97
8.0.80.0060.00916.92
8.0.70.0060.00316.90
8.0.60.0040.00416.78
8.0.50.0030.00516.81
8.0.30.0100.00917.00
8.0.20.0120.00817.40
8.0.10.0080.00017.09
8.0.00.0090.01116.70
7.4.330.0000.00515.55
7.4.320.0060.00016.55
7.4.300.0030.00316.64
7.4.290.0040.00416.64
7.4.280.0020.00516.54
7.4.270.0070.00016.63
7.4.260.0030.00316.48
7.4.250.0000.00716.50
7.4.240.0050.00216.55
7.4.230.0000.00716.54
7.4.220.0030.00616.62
7.4.210.0090.00616.41
7.4.200.0060.00316.53
7.4.160.0120.00616.62
7.4.150.0140.00317.40
7.4.140.0110.00917.86
7.4.130.0080.01116.77
7.4.120.0120.00716.57
7.4.110.0100.00716.48
7.4.100.0130.00316.54
7.4.90.0090.00916.41
7.4.80.0090.00919.39
7.4.70.0090.01116.52
7.4.60.0120.00416.68
7.4.50.0030.01216.49
7.4.40.0040.01216.75
7.4.00.0090.00914.75
7.3.330.0050.00013.37
7.3.320.0030.00313.48
7.3.310.0000.00716.26
7.3.300.0030.00316.35
7.3.290.0120.00816.39
7.3.280.0130.00316.38
7.3.270.0030.01417.40
7.3.260.0110.00716.34
7.3.250.0140.00416.50
7.3.240.0090.01016.44
7.3.230.0030.01416.28
7.3.210.0120.00416.59
7.3.200.0100.00616.48
7.3.190.0100.00716.36
7.3.180.0130.00316.54
7.3.170.0150.00416.57
7.3.160.0060.01016.66
7.2.330.0100.01016.79
7.2.320.0080.00816.64
7.2.310.0100.00616.83
7.2.300.0030.01316.82
7.2.290.0150.00016.91
7.2.60.1410.00814.90
7.2.50.1860.00914.95
7.2.40.1870.00915.53
7.2.30.2870.00915.62
7.2.20.2070.01115.58
7.2.10.0870.01217.32
7.2.00.0770.00817.22
7.1.200.0060.00615.61
7.1.170.1660.00913.68
7.1.160.2010.01217.00
7.1.150.1990.00716.90
7.1.140.1730.01417.03
7.1.130.0730.00816.89
7.1.120.0750.00917.04
7.1.110.0820.01016.41
7.1.100.0810.00716.42
7.1.90.0900.00816.40
7.1.80.0930.00816.28
7.1.70.0810.01015.47
7.1.60.0850.00933.20
7.1.50.0970.00832.98
7.1.40.1300.01032.76
7.1.30.0990.01232.67
7.1.20.1040.01232.72
7.1.10.0790.00814.86
7.1.00.0880.01014.83

preferences:
32.3 ms | 403 KiB | 5 Q