3v4l.org

run code in 300+ PHP versions simultaneously
<?php function elapsed_time(array $start) { $now = explode(' ', microtime()); $deltasec = $now[1] - $start[1]; $deltamsec = (float)$now[0] - (float)$start[0]; return $deltasec + $deltamsec; } $str = 'This thing should output _$this_key$_ and also _$this_one$_ so that I can match it with an array!'; $replacements = [ 'this_key' => 'love', 'this_one' => 'more love' ]; $start = '_$'; $end = '$_'; $new_reps = array(); $starttime = explode(' ', microtime()); for ($i = 0; $i < 10000; $i++) { foreach ($replacements as $key => $value) { $new_reps["_\$$key\$_"] = $value; } $output = strtr($str, $new_reps); } echo "$output\n"; echo "strtr: " . elapsed_time($starttime) . "\n"; $replacements = [ 'this_key' => 'love', 'this_one' => 'more love' ]; $starttime = explode(' ', microtime()); for ($i = 0; $i < 10000; $i++) { $replaced = preg_replace_callback('/_\$([^$]+)\$_/', function($matches) use ($replacements) { return $replacements[$matches[1]]; }, $str); } echo "preg_replace: " . elapsed_time($starttime) . "\n"; echo "$replaced\n";

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.2.00.0060.01218.05
8.1.130.0060.01617.48
8.1.120.0070.01417.68
8.1.110.0070.01417.68
8.1.100.0060.01617.59
8.1.90.0090.01517.53
8.1.80.0090.01617.59
8.1.70.0100.01417.62
8.1.60.0100.01517.71
8.1.50.0030.01717.63
8.1.40.0100.01117.63
8.1.30.0020.01817.80
8.1.20.0070.01417.77
8.1.10.0070.01417.67
8.1.00.0090.01917.67
8.0.260.0140.01017.09
8.0.250.0110.01417.08
8.0.240.0080.02017.03
8.0.230.0110.01417.09
8.0.220.0100.01516.93
8.0.210.0110.01416.99
8.0.200.0110.01417.07
8.0.190.0070.01717.07
8.0.180.0100.01417.10
8.0.170.0070.01717.06
8.0.160.0060.01917.08
8.0.150.0170.00817.01
8.0.140.0080.01617.02
8.0.130.0130.01216.95
8.0.120.0100.01516.99
8.0.110.0110.01417.03
8.0.100.0100.01417.05
8.0.90.0110.01316.98
8.0.80.0090.01517.03
8.0.70.0080.01617.03
8.0.60.0090.01416.99
8.0.50.0110.01217.06
8.0.30.0080.01616.96
8.0.20.0090.01517.07
8.0.10.0100.01417.20
8.0.00.0050.01917.12
7.4.330.0080.01713.96
7.4.320.0090.01916.67
7.4.300.0100.01416.67
7.4.290.0110.01416.67
7.4.280.0110.01316.68
7.4.270.0070.01916.65
7.4.260.0090.01416.58
7.4.250.0120.01316.70
7.4.240.0140.01016.73
7.4.230.0130.01216.70
7.4.220.0080.01616.64
7.4.210.0120.01216.68
7.4.200.0070.01516.66
7.4.190.0040.01916.64
7.4.180.0150.01016.79
7.4.160.0140.01116.79
7.4.150.0090.01516.65
7.4.140.0100.01316.65
7.4.130.0080.01516.63
7.4.120.0090.01316.67
7.4.110.0090.01616.64
7.4.100.0120.01216.71
7.4.90.0060.01816.69
7.4.80.0080.01416.68
7.4.70.0070.01416.70
7.4.60.0050.01516.65
7.4.50.0050.01716.64
7.4.40.0050.01816.59
7.4.30.0110.01216.65
7.4.20.0020.02016.64
7.4.10.0090.01916.52
7.4.00.0090.01716.73
7.3.330.0090.01616.45
7.3.320.0050.02016.55
7.3.310.0110.01316.35
7.3.300.0110.01416.39
7.3.290.0140.01216.51
7.3.280.0150.01016.54
7.3.270.0110.01416.38
7.3.260.0060.01816.43
7.3.250.0150.01116.41
7.3.240.0130.01116.43
7.3.230.0100.01516.50
7.3.220.0110.01416.44
7.3.210.0110.01416.42
7.3.200.0080.01716.44
7.3.190.0130.01216.30
7.3.180.0070.02116.37
7.3.170.0150.01216.30
7.3.160.0080.01716.44
7.3.150.0130.01316.40
7.3.140.0080.01716.34
7.3.130.0130.01616.40
7.3.120.0100.02116.36
7.3.110.0130.01816.31
7.3.100.0120.02216.35
7.3.90.0110.01916.65
7.3.80.0080.02016.46
7.3.70.0080.02016.50
7.3.60.0120.02016.56
7.3.50.0140.01916.59
7.3.40.0080.02016.57
7.3.30.0120.01516.59
7.3.20.0120.02117.20
7.3.10.0150.02217.20
7.3.00.0130.01517.17
7.2.340.0100.01516.55
7.2.330.0100.01616.50
7.2.320.0140.01216.69
7.2.310.0090.01716.57
7.2.300.0150.01216.71
7.2.290.0110.01516.60
7.2.280.0110.01516.65
7.2.270.0090.01816.56
7.2.260.0090.02316.67
7.2.250.0130.02016.54
7.2.240.0120.02216.70
7.2.230.0070.02516.79
7.2.220.0110.01916.61
7.2.210.0070.02316.68
7.2.200.0130.02416.79
7.2.190.0080.02816.66
7.2.180.0120.02416.72
7.2.170.0050.02416.71
7.2.160.0080.02116.75
7.2.150.0140.02017.36
7.2.140.0140.01517.43
7.2.130.0100.01917.51
7.2.120.0250.02217.49
7.2.110.0110.02517.39
7.2.100.0100.02017.43
7.2.90.0110.02617.33
7.2.80.0080.02217.54
7.2.70.0160.01517.45
7.2.60.0080.02117.40
7.2.50.0170.01917.46
7.2.40.0090.02717.46
7.2.30.0090.02917.44
7.2.20.0100.02117.47
7.2.10.0140.02317.49
7.2.00.0100.02117.48

preferences:
36.53 ms | 403 KiB | 5 Q