3v4l.org

run code in 300+ PHP versions simultaneously
<?php function mb_str_replace($search, $replace, $subject, $encoding = 'auto') { if(!is_array($search)) { $search = array($search); } if(!is_array($replace)) { $replace = array($replace); } if(strtolower($encoding) === 'auto') { $encoding = mb_internal_encoding(); } // $subject が複数ならば各要素に繰り返し適用する if(is_array($subject) || $subject instanceof Traversable) { $result = array(); foreach($subject as $key => $val) { $result[$key] = mb_str_replace($search, $replace, $val, $encoding); } return $result; } $currentpos = 0; // 現在の検索開始位置 while(true) { // $currentpos 以降で $search のいずれかが現れる位置を検索する $index = -1; // 見つけた文字列(最も前にあるもの)の $search の index $minpos = -1; // 見つけた文字列(最も前にあるもの)の位置 foreach($search as $key => $find) { if($find == '') { continue; } $findpos = mb_strpos($subject, $find, $currentpos, $encoding); if($findpos !== false) { if($minpos < 0 || $findpos < $minpos) { $minpos = $findpos; $index = $key; } } } // $search のいずれも見つからなければ終了 if($minpos < 0) { break; } // 置換実行 $r = array_key_exists($index, $replace) ? $replace[$index] : ''; $subject = mb_substr($subject, 0, $minpos, $encoding) . // 置換開始位置より前 $r . // 置換後文字列 mb_substr( // 置換終了位置より後ろ $subject, $minpos + mb_strlen($search[$index], $encoding), mb_strlen($subject, $encoding), $encoding); // 「現在位置」を $r の直後に設定 $currentpos = $minpos + mb_strlen($r, $encoding); } return $subject; } $test = 'this is {$tableName} test'; echo mb_str_replace('{$tableName}', 'timecard', $test);

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.0110.01118.55
8.3.50.0160.00722.05
8.3.40.0080.00818.98
8.3.30.0040.01120.34
8.3.20.0040.00420.34
8.3.10.0060.00321.90
8.3.00.0040.00422.45
8.2.180.0070.01416.63
8.2.170.0120.00322.96
8.2.160.0070.00720.29
8.2.150.0040.00424.18
8.2.140.0040.00424.66
8.2.130.0080.00026.16
8.2.120.0030.00519.53
8.2.110.0040.00422.25
8.2.100.0070.00719.40
8.2.90.0060.00319.17
8.2.80.0030.00619.38
8.2.70.0050.00517.38
8.2.60.0060.00317.93
8.2.50.0030.00618.07
8.2.40.0020.00518.16
8.2.30.0050.00318.14
8.2.20.0050.00317.67
8.2.10.0040.00417.76
8.2.00.0070.00317.73
8.1.280.0070.00725.92
8.1.270.0040.00424.66
8.1.260.0040.00426.35
8.1.250.0040.00428.09
8.1.240.0030.00623.82
8.1.230.0040.00719.04
8.1.220.0040.00417.74
8.1.210.0040.00418.77
8.1.200.0050.00517.35
8.1.190.0080.00017.43
8.1.180.0000.00819.01
8.1.170.0000.00818.54
8.1.160.0040.00422.19
8.1.150.0050.00318.64
8.1.140.0040.00417.39
8.1.130.0030.00317.76
8.1.120.0000.00817.47
8.1.110.0000.00717.50
8.1.100.0000.00717.43
8.1.90.0040.00417.32
8.1.80.0040.00417.46
8.1.70.0030.00317.52
8.1.60.0000.00917.62
8.1.50.0000.00817.48
8.1.40.0040.00417.45
8.1.30.0030.00517.68
8.1.20.0040.00417.73
8.1.10.0030.00517.64
8.1.00.0030.00717.51
8.0.300.0070.00018.77
8.0.290.0080.00017.30
8.0.280.0030.00318.51
8.0.270.0030.00317.33
8.0.260.0070.00016.95
8.0.250.0040.00417.06
8.0.240.0090.00017.06
8.0.230.0040.00416.98
8.0.220.0030.00317.02
8.0.210.0000.00716.91
8.0.200.0000.00717.03
8.0.190.0040.00417.05
8.0.180.0000.00717.03
8.0.170.0040.00417.02
8.0.160.0040.00416.89
8.0.150.0070.00016.96
8.0.140.0000.00816.89
8.0.130.0030.00313.41
8.0.120.0040.00417.02
8.0.110.0030.00516.92
8.0.100.0000.00716.95
8.0.90.0030.00516.98
8.0.80.0100.00616.92
8.0.70.0070.00017.06
8.0.60.0040.00417.08
8.0.50.0000.00817.00
8.0.30.0120.01117.16
8.0.20.0130.00517.40
8.0.10.0040.00417.10
8.0.00.0100.01016.69
7.4.330.0020.00215.00
7.4.320.0040.00416.56
7.4.300.0030.00316.46
7.4.290.0030.00316.62
7.4.280.0070.00016.64
7.4.270.0030.00316.52
7.4.260.0030.00316.59
7.4.250.0000.00716.58
7.4.240.0040.00416.47
7.4.230.0030.00316.46
7.4.220.0070.01016.64
7.4.210.0080.00816.61
7.4.200.0030.00316.68
7.4.190.0070.00016.52
7.4.160.0030.01316.47
7.4.150.0150.00317.40
7.4.140.0090.00917.86
7.4.130.0100.00716.62
7.4.120.0080.00916.53
7.4.110.0150.00916.39
7.4.100.0120.01616.69
7.4.90.0130.00716.52
7.4.80.0070.01019.39
7.4.70.0180.00016.46
7.4.60.0100.00716.47
7.4.50.0050.00016.53
7.4.40.0070.00722.77
7.4.30.0090.01216.64
7.4.00.0030.01315.14
7.3.330.0000.00513.23
7.3.320.0000.00613.40
7.3.310.0070.00016.49
7.3.300.0030.00316.33
7.3.290.0040.01116.44
7.3.280.0080.00816.44
7.3.270.0100.00717.40
7.3.260.0110.00716.69
7.3.250.0120.00616.45
7.3.240.0070.01116.68
7.3.230.0140.00416.64
7.3.210.0100.00616.47
7.3.200.0060.01519.39
7.3.190.0150.00316.43
7.3.180.0080.00816.49
7.3.170.0080.00816.61
7.3.160.0100.01316.45
7.3.120.0070.00714.79
7.2.330.0190.00016.80
7.2.320.0140.00316.64
7.2.310.0070.01016.72
7.2.300.0080.00816.41
7.2.290.0090.00616.48
7.2.00.0030.00719.41
7.1.200.0000.01315.57
7.1.100.0100.00318.35
7.1.70.0000.00717.02
7.1.60.0110.01519.43
7.1.50.0060.01917.12
7.1.00.0000.03722.34
7.0.200.0000.00816.53
7.0.140.0030.07321.98
7.0.100.0030.08720.02
7.0.90.0070.05019.94
7.0.80.0170.07020.15
7.0.70.0030.08319.92
7.0.60.0130.07719.97
7.0.50.0070.08320.33
7.0.40.0130.08020.18
7.0.30.0130.08020.11
7.0.20.0200.04720.02
7.0.10.0100.08320.18
7.0.00.0130.08319.95
5.6.250.0070.05320.71
5.6.240.0030.09020.77
5.6.230.0070.09020.75
5.6.220.0100.04720.60
5.6.210.0130.04720.47
5.6.200.0170.07320.98
5.6.190.0130.06721.07
5.6.180.0070.04321.13
5.6.170.0130.07321.19
5.6.160.0070.06721.02
5.6.150.0100.06721.19
5.6.140.0070.08321.18
5.6.130.0000.07321.01
5.6.120.0100.08721.07
5.6.110.0100.08321.03
5.6.100.0070.08720.94
5.6.90.0030.08021.05
5.6.80.0100.06320.54
5.6.70.0030.05320.57
5.6.60.0100.06720.47
5.6.50.0200.06320.44
5.6.40.0070.07720.38
5.6.30.0130.07020.48
5.6.20.0130.07320.39
5.6.10.0030.08320.36
5.6.00.0130.07320.39
5.5.380.0070.08720.44
5.5.370.0100.04720.43
5.5.360.0100.07720.38
5.5.350.0170.07720.39
5.5.340.0100.07720.75
5.5.330.0270.06720.79
5.5.320.0070.08320.93
5.5.310.0200.07320.94
5.5.300.0070.07720.93
5.5.290.0030.09320.93
5.5.280.0070.08720.79
5.5.270.0070.08020.65
5.5.260.0130.07720.79
5.5.250.0170.03320.70
5.5.240.0100.04320.23
5.5.230.0000.05020.17
5.5.220.0300.05720.19
5.5.210.0130.07320.27
5.5.200.0070.04720.13
5.5.190.0070.08320.24
5.5.180.0200.06720.24
5.5.160.0100.07320.29
5.5.150.0070.08020.23
5.5.140.0070.07720.25
5.5.130.0030.08020.28
5.5.120.0100.06320.19
5.5.110.0200.06720.22
5.5.100.0030.07719.97
5.5.90.0030.08020.03
5.5.80.0100.07720.11
5.5.70.0130.04020.11
5.5.60.0070.08020.08
5.5.50.0100.05320.16
5.5.40.0070.06720.05
5.5.30.0070.07720.14
5.5.20.0130.07320.15
5.5.10.0070.07320.03
5.5.00.0070.08020.04
5.4.450.0070.05719.54
5.4.440.0130.07719.37
5.4.430.0100.04719.42
5.4.420.0100.04719.54
5.4.410.0070.08019.38
5.4.400.0070.07719.05
5.4.390.0130.07019.09
5.4.380.0230.06719.15
5.4.370.0100.05019.04
5.4.360.0030.05018.87
5.4.350.0130.06719.04
5.4.340.0030.08019.13
5.4.320.0070.08319.13
5.4.310.0070.07719.03
5.4.300.0030.07719.00
5.4.290.0070.07019.12
5.4.280.0130.07319.22
5.4.270.0100.04019.09
5.4.260.0070.07719.13
5.4.250.0000.07319.16
5.4.240.0000.07319.13
5.4.230.0100.07719.02
5.4.220.0100.07019.12
5.4.210.0100.04719.04
5.4.200.0000.05018.89
5.4.190.0070.05719.03
5.4.180.0070.07319.02
5.4.170.0130.07019.11
5.4.160.0100.07319.18
5.4.150.0030.08019.11
5.4.140.0070.07716.42
5.4.130.0130.06016.19
5.4.120.0200.06016.40
5.4.110.0070.04316.50
5.4.100.0100.06716.48
5.4.90.0070.06716.48
5.4.80.0070.07316.34
5.4.70.0130.06716.46
5.4.60.0100.06716.30
5.4.50.0130.06316.42
5.4.40.0070.07016.35
5.4.30.0000.04716.41
5.4.20.0100.06716.40
5.4.10.0030.07716.32
5.4.00.0030.07715.63
5.3.290.0070.07314.66
5.3.280.0170.06314.66
5.3.270.0100.04314.63
5.3.260.0100.07714.76
5.3.250.0100.05314.72
5.3.240.0100.06314.61
5.3.230.0030.07714.64
5.3.220.0130.06714.59
5.3.210.0130.07714.57
5.3.200.0100.07314.64
5.3.190.0070.07014.58
5.3.180.0070.06714.51
5.3.170.0100.06014.60
5.3.160.0030.04014.51
5.3.150.0000.04314.60
5.3.140.0070.07714.68
5.3.130.0130.06714.57
5.3.120.0030.08014.66
5.3.110.0000.05014.55
5.3.100.0100.04714.24
5.3.90.0130.04014.24
5.3.80.0100.07014.24
5.3.70.0070.04314.24
5.3.60.0170.06314.24
5.3.50.0170.06314.24
5.3.40.0170.05714.24
5.3.30.0070.04314.24
5.3.20.0100.07314.24
5.3.10.0100.03714.24
5.3.00.0100.06314.24
5.2.170.0030.05314.24
5.2.160.0030.04314.24
5.2.150.0070.05714.24
5.2.140.0100.05014.24
5.2.130.0130.04314.24
5.2.120.0100.06014.24
5.2.110.0030.06314.24
5.2.100.0100.05714.24
5.2.90.0070.06014.24
5.2.80.0100.05714.24
5.2.70.0000.06714.24
5.2.60.0030.06314.24
5.2.50.0030.06714.24
5.2.40.0100.03314.24
5.2.30.0070.05314.24
5.2.20.0070.04314.24
5.2.10.0000.06314.24
5.2.00.0030.06014.24
5.1.60.0070.04014.24
5.1.50.0030.05314.24
5.1.40.0070.03714.24
5.1.30.0030.05714.24
5.1.20.0070.04714.24
5.1.10.0070.03014.24
5.1.00.0070.05014.24
5.0.50.0070.04314.24
5.0.40.0030.04714.24
5.0.30.0000.07014.24
5.0.20.0030.04314.24
5.0.10.0030.04314.24
5.0.00.0030.06014.24
4.4.90.0030.03714.24
4.4.80.0000.03314.24
4.4.70.0030.03314.24
4.4.60.0000.03714.24
4.4.50.0030.03714.24
4.4.40.0070.04714.24
4.4.30.0030.01714.24
4.4.20.0030.03314.24
4.4.10.0070.03014.24
4.4.00.0030.05014.24
4.3.110.0070.01714.24
4.3.100.0030.03314.24
4.3.90.0000.03314.24
4.3.80.0030.03714.24
4.3.70.0070.03014.24
4.3.60.0000.03714.24
4.3.50.0030.03314.24
4.3.40.0030.05014.24
4.3.30.0070.03014.24
4.3.20.0070.03314.24
4.3.10.0100.03014.24
4.3.00.0000.03714.24

preferences:
58.65 ms | 400 KiB | 5 Q