3v4l.org

run code in 500+ PHP versions simultaneously
<?php function substrStrpos($text) { return substr($text, 1 + (strpos($text, ' ') ?: -1)); } function explodeSlice($text) { $explodeOnce = explode(' ', $text, 2); return array_pop($explodeOnce); } function substrStrstr($text) { return substr(strstr($text, " "), 1); } function ltrimStrstr($text) { return ltrim(strstr($text, " ")); } function pregReplace($text) { return preg_replace('~^\S+\s*~', '', $text); } $tests = [ '' => '', 'White' => '', 'White Tank' => 'Tank', 'White Tank Top' => 'Tank Top', ]; printf("| %14s| [empty] | White | White Tank | White Tank Top |\n", 'func \ tests'); $funcs = [ 'substrStrpos', 'explodeSlice', 'substrStrstr', 'ltrimStrstr', 'pregReplace', ]; foreach ($funcs as $func) { echo "------------------------------------------------------------------------\n"; printf( "| %14s| %s | %s | %s | %s |\n", $func, ...array_map( fn($result, $expected) => $result === $expected ? '✅': '💩', array_map($func, array_keys($tests)), $tests ) ); } echo "\n\n---\n"; var_export(substrStrpos('White')); echo "\n\n---\n"; var_export(explodeSlice('White'));

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.70.0090.00616.74
8.5.60.0130.00516.80
8.5.50.0110.00616.88
8.5.30.0100.00719.69
8.5.20.0100.00920.09
8.5.10.0100.00818.49
8.5.00.0120.01020.36
8.4.220.0100.01323.83
8.4.210.0130.00919.73
8.4.180.0110.01225.75
8.4.170.0090.01224.11
8.4.160.0110.01121.65
8.4.150.0090.00316.98
8.4.140.0150.00817.59
8.4.130.0110.01019.72
8.4.120.0040.00420.67
8.4.110.0110.01018.70
8.4.100.0120.00818.88
8.4.90.0160.00518.88
8.4.80.0140.00620.39
8.4.70.0130.00718.20
8.4.60.0090.00218.79
8.4.50.0140.00618.92
8.4.40.0100.00618.57
8.4.30.0160.00318.93
8.4.20.0100.01019.77
8.4.10.0000.00819.48
8.3.310.0100.00618.68
8.3.300.0110.01020.70
8.3.290.0110.01022.77
8.3.280.0150.00818.54
8.3.270.0100.01116.99
8.3.260.0160.00416.75
8.3.250.0140.00519.04
8.3.240.0100.00917.11
8.3.230.0040.00416.96
8.3.220.0060.00219.18
8.3.210.0080.00617.09
8.3.200.0050.00316.61
8.3.190.0130.00617.22
8.3.180.0090.00617.43
8.3.170.0100.01018.93
8.3.160.0070.01117.26
8.3.150.0090.00916.99
8.3.140.0160.00016.61
8.3.130.0090.00018.43
8.3.120.0160.00320.81
8.3.110.0000.00920.94
8.3.100.0100.01018.51
8.3.90.0150.00326.77
8.3.80.0090.00019.36
8.3.70.0100.00616.71
8.3.60.0300.01325.92
8.3.50.0150.00625.92
8.3.40.0310.00725.92
8.3.30.0420.00325.92
8.3.20.0320.01125.92
8.3.10.0220.01525.92
8.3.00.0370.00725.92
8.2.310.0100.01118.39
8.2.300.0100.01022.20
8.2.290.0140.00520.46
8.2.280.0100.01018.49
8.2.270.0050.00317.44
8.2.260.0060.00918.65
8.2.250.0040.00418.66
8.2.240.0000.00917.27
8.2.230.0070.00722.58
8.2.220.0080.00024.06
8.2.210.0060.01226.77
8.2.200.0000.01018.88
8.2.190.0130.00616.88
8.2.180.0190.00325.92
8.2.170.0300.01325.92
8.2.160.0350.00625.92
8.2.150.0320.01125.92
8.2.140.0450.00625.92
8.2.130.0610.00325.92
8.2.120.0420.00325.92
8.2.110.0430.01225.92
8.2.100.0340.00325.92
8.2.90.0310.00325.92
8.2.80.0280.01225.92
8.2.70.0340.00725.92
8.2.60.0330.01025.92
8.2.50.0330.01125.92
8.2.40.0350.00325.92
8.2.30.0360.00525.92
8.2.20.0340.00925.92
8.2.10.0330.01125.92
8.2.00.0270.01225.92
8.1.340.0110.01017.69
8.1.330.0130.00621.86
8.1.320.0060.00516.20
8.1.310.0030.00618.35
8.1.300.0030.00717.74
8.1.290.0090.00030.84
8.1.280.0280.01325.92
8.1.270.0360.01325.92
8.1.260.0420.00825.92
8.1.250.0310.00825.92
8.1.240.0330.00425.92
8.1.230.0330.01225.92
8.1.220.0280.00825.92
8.1.210.0250.00925.92
8.1.200.0240.01225.92
8.1.190.0210.01525.92
8.1.180.0290.00625.92
8.1.170.0280.00625.92
8.1.160.0310.00425.92
8.1.150.0280.01025.92
8.1.140.0280.00725.92
8.1.130.0260.00325.92
8.1.120.0230.00625.92
8.1.110.0340.00325.92
8.1.100.0330.00325.92
8.1.90.0270.00325.92
8.1.80.0260.00425.92
8.1.70.0190.00925.92
8.1.60.0190.01125.92
8.1.50.0220.00925.92
8.1.40.0180.01425.92
8.1.30.0330.00025.92
8.1.20.0270.00725.92
8.1.10.0260.00625.92
8.1.00.0340.00325.92

preferences:
54.44 ms | 1118 KiB | 5 Q