3v4l.org

run code in 300+ PHP versions simultaneously
<?PHP $str = " Monday Tuesday Wednesday Thursday Friday\nSaturday\tSunday"; function a($str) { return str_word_count($str,1,"!\"#$%&'()*+,./0123456789-:;<=>?@[\]^_`{|}~"); }; function c($str) { return preg_split("/\s+/",trim($str)); }; function d($string){ return array_filter(explode(' ', implode(' ', array_map('trim', explode("\n", $string))))); }; function e($str) { $str = trim($str); $words = array(); $len = strlen($str); $word = ''; for ($i = 0; $i < $len; $i++) { $char = $str[$i]; $ord = ord($char); // Is a character if ($ord > 32 && $ord < 127) { $word .= $char; // It's some sort of whitespace } else { if ($word) { $words[] = $word; } $word = ''; } } if ($word) { $words[] = $word; } return $words; }; function f($str,$return_hash = false) { $str = trim($str); // Word characters are any printable char $words = str_word_count($str,1,"!\"#$%&'()*+,./0123456789-:;<=>?@[\]^_`{|}~"); if ($return_hash) { $ret = array(); $num = sizeof($words); // Odd number of elements, can't build a hash if ($num % 2 == 1) { return array(); } else { // Loop over each word and build a key/value hash for ($i = 0; $i < $num; $i += 2) { $key = $words[$i]; $value = $words[$i + 1]; $ret[$key] = $value; } return $ret; } } else { return $words; } }; a($str); c($str); d($str); e($str); f($str);

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.0070.01119.09
8.3.30.0120.00319.14
8.3.20.0040.00420.27
8.3.10.0040.00421.95
8.3.00.0080.00019.63
8.2.170.0070.00722.96
8.2.160.0100.00320.35
8.2.150.0090.00024.18
8.2.140.0040.00424.66
8.2.130.0030.00626.16
8.2.120.0030.00519.48
8.2.110.0030.00621.07
8.2.100.0080.00418.00
8.2.90.0000.00819.26
8.2.80.0000.00917.97
8.2.70.0030.00617.88
8.2.60.0000.00818.16
8.2.50.0080.00018.07
8.2.40.0040.00420.07
8.2.30.0080.00018.27
8.2.20.0040.00417.95
8.2.10.0030.00518.11
8.2.00.0000.00717.86
8.1.270.0090.00020.73
8.1.260.0000.00726.35
8.1.250.0040.00428.09
8.1.240.0090.00022.22
8.1.230.0070.00417.78
8.1.220.0040.00417.88
8.1.210.0050.00318.77
8.1.200.0030.00617.60
8.1.190.0050.00317.48
8.1.180.0040.00418.10
8.1.170.0030.00618.96
8.1.160.0000.00722.00
8.1.150.0040.00419.01
8.1.140.0040.00417.67
8.1.130.0080.00017.89
8.1.120.0030.00617.52
8.1.110.0000.00917.68
8.1.100.0040.00417.52
8.1.90.0050.00217.69
8.1.80.0030.00317.66
8.1.70.0000.00917.63
8.1.60.0060.00317.80
8.1.50.0040.00417.67
8.1.40.0020.00517.62
8.1.30.0030.00517.75
8.1.20.0000.00817.76
8.1.10.0040.00417.72
8.1.00.0030.00617.71
8.0.300.0060.00318.77
8.0.290.0040.00416.73
8.0.280.0030.00318.52
8.0.270.0030.00317.31
8.0.260.0060.00017.32
8.0.250.0000.00717.06
8.0.240.0000.00817.02
8.0.230.0040.00417.11
8.0.220.0070.00016.98
8.0.210.0000.00717.09
8.0.200.0060.00017.04
8.0.190.0000.00817.13
8.0.180.0000.00817.07
8.0.170.0040.00417.09
8.0.160.0070.00017.11
8.0.150.0040.00417.11
8.0.140.0000.00817.01
8.0.130.0030.00313.52
8.0.120.0030.00517.07
8.0.110.0020.00516.99
8.0.100.0040.00416.91
8.0.90.0040.00416.88
8.0.80.0090.00617.06
8.0.70.0040.00417.11
8.0.60.0070.00016.96
8.0.50.0050.00316.99
8.0.30.0050.00517.09
8.0.20.0170.00217.44
8.0.10.0020.00517.16
8.0.00.0130.00817.07
7.4.330.0000.00515.03
7.4.320.0000.00616.87
7.4.300.0040.00416.91
7.4.290.0100.00016.63
7.4.280.0050.00216.79
7.4.270.0070.00016.76
7.4.260.0040.00416.74
7.4.250.0030.00516.85
7.4.240.0000.00716.83
7.4.230.0030.00316.92
7.4.220.0120.01816.71
7.4.210.0100.00816.78
7.4.200.0000.00716.84
7.4.160.0130.00316.75
7.4.150.0140.00317.40
7.4.140.0120.00717.86
7.4.130.0080.01216.76
7.4.120.0100.00716.83
7.4.110.0150.00616.78
7.4.100.0140.00316.68
7.4.90.0110.00716.60
7.4.80.0110.00519.39
7.4.70.0000.01616.73
7.4.60.0080.01616.72
7.4.50.0000.00816.68
7.4.40.0140.00316.67
7.4.30.0090.00716.98
7.4.10.0070.01014.94
7.4.00.0080.00815.08
7.3.330.0000.00713.36
7.3.320.0050.01113.38
7.3.310.0000.00816.61
7.3.300.0030.00316.46
7.3.290.0000.00716.52
7.3.280.0070.00816.49
7.3.270.0110.00817.40
7.3.260.0070.01016.51
7.3.250.0100.00916.77
7.3.240.0040.01416.53
7.3.230.0060.01216.50
7.3.210.0060.01716.54
7.3.200.0130.00719.39
7.3.190.0080.00816.46
7.3.180.0120.00616.37
7.3.170.0070.01016.81
7.3.160.0060.01116.69
7.3.130.0040.01515.00
7.3.120.0190.00015.17
7.3.110.0120.00615.07
7.3.100.0060.00915.25
7.3.90.0030.00615.00
7.3.80.0060.00615.08
7.3.70.0070.01014.85
7.3.60.0090.00615.06
7.3.50.0030.00915.20
7.3.40.0060.00315.16
7.3.30.0000.01414.97
7.3.20.0090.00616.83
7.3.10.0120.00716.80
7.3.00.0120.00316.63
7.2.330.0130.00316.92
7.2.320.0090.00916.98
7.2.310.0140.00316.77
7.2.300.0060.01016.88
7.2.290.0030.01416.83
7.2.260.0030.01615.28
7.2.250.0110.00715.24
7.2.240.0070.00715.27
7.2.230.0040.01015.29
7.2.220.0030.01314.89
7.2.210.0060.00315.41
7.2.200.0030.00615.28
7.2.190.0120.00415.04
7.2.180.0120.00315.41
7.2.170.0040.01115.34
7.2.160.0000.01215.25
7.2.150.0000.01217.35
7.2.140.0030.00917.23
7.2.130.0130.00616.93
7.2.120.0060.00916.68
7.2.110.0110.00516.78
7.2.100.0060.00916.82
7.2.90.0090.00716.98
7.2.80.0080.01016.74
7.2.70.0140.00516.70
7.2.60.0120.00816.96
7.2.50.0050.01216.94
7.2.40.0090.00616.62
7.2.30.0090.00616.76
7.2.20.0050.01116.71
7.2.10.0070.00816.98
7.2.00.0090.00917.85
7.1.330.0090.00616.04
7.1.320.0110.00716.07
7.1.310.0110.00415.89
7.1.300.0000.01515.96
7.1.290.0090.00616.00
7.1.280.0070.01016.07
7.1.270.0090.00616.04
7.1.260.0000.01116.05
7.1.250.0050.01215.89
7.1.240.0070.00715.85
7.1.230.0040.00716.21
7.1.220.0040.00415.95
7.1.210.0030.00915.96
7.1.200.0030.00515.82
7.1.190.0000.01215.83
7.1.180.0070.00715.64
7.1.170.0030.01015.80
7.1.160.0070.00715.88
7.1.150.0080.00615.99
7.1.140.0000.00916.02
7.1.130.0070.00715.99
7.1.120.0030.00615.91
7.1.110.0000.01515.85
7.1.100.0050.01117.22
7.1.90.0110.00015.91
7.1.80.0030.01015.92
7.1.70.0020.00916.75
7.1.60.0050.01417.67
7.1.50.0070.00716.57
7.1.40.0000.01415.63
7.1.30.0040.00716.11
7.1.20.0040.00815.97
7.1.10.0110.00415.83
7.1.00.0020.04419.30
7.0.330.0100.00015.52
7.0.320.0030.01015.39
7.0.310.0000.00815.64
7.0.300.0070.00715.64
7.0.290.0100.00315.73
7.0.280.0030.00715.69
7.0.270.0110.00315.66
7.0.260.0030.00915.44
7.0.250.0090.00015.62
7.0.240.0070.00715.59
7.0.230.0060.00615.43
7.0.220.0030.00815.75
7.0.210.0060.00615.82
7.0.200.0200.00116.08
7.0.190.0030.01015.45
7.0.180.0040.01115.52
7.0.170.0000.01015.59
7.0.160.0030.00615.80
7.0.150.0030.01315.47
7.0.140.0060.04018.90
7.0.130.0110.00015.29
7.0.120.0040.00815.49
7.0.110.0060.00615.64
7.0.100.0070.00315.70
7.0.90.0030.01015.36
7.0.80.0030.01215.32
7.0.70.0040.00715.62
7.0.60.0190.04017.59
7.0.50.0130.03316.75
7.0.40.0110.03417.05
7.0.30.0140.03716.95
7.0.20.0180.03517.01
7.0.10.0080.04816.96
7.0.00.0030.05116.85
5.6.400.0120.00314.62
5.6.390.0070.00714.65
5.6.380.0100.00314.46
5.6.370.0080.00314.34
5.6.360.0000.00814.43
5.6.350.0000.01214.32
5.6.340.0090.00914.36
5.6.330.0100.00714.92
5.6.320.0100.00314.84
5.6.310.0110.00314.60
5.6.300.0040.01214.26
5.6.290.0120.00314.88
5.6.280.0070.03517.64
5.6.270.0000.01314.47
5.6.260.0080.00414.66
5.6.250.0030.00614.73
5.6.240.0000.01014.48
5.6.230.0080.00414.36
5.6.220.0000.01414.43
5.6.210.0080.04117.48
5.6.200.0070.04116.46
5.6.190.0100.04017.47
5.6.180.0100.04417.62
5.6.170.0100.02717.44
5.6.160.0050.04017.50
5.6.150.0110.01916.27
5.6.140.0070.03216.44
5.6.130.0080.03416.37
5.6.120.0050.04517.81
5.6.110.0060.04317.65
5.6.100.0000.05117.58
5.6.90.0120.04317.81
5.6.80.0070.04217.41
5.6.70.0110.00714.45
5.6.60.0030.00914.40
5.6.50.0100.00614.19
5.6.40.0060.00814.73
5.6.30.0070.00314.58
5.6.20.0000.01214.63
5.6.10.0040.01114.55
5.6.00.0060.00914.49
5.5.380.0070.00714.36
5.5.370.0060.00314.22
5.5.360.0030.00914.42
5.5.350.2180.02517.40
5.5.340.0050.03216.34
5.5.330.0050.02517.52
5.5.320.0160.02717.47
5.5.310.0240.03517.45
5.5.300.0050.02316.22
5.5.290.0070.03316.39
5.5.280.0140.03717.71
5.5.270.0060.03517.63
5.5.260.0030.03617.64
5.5.250.0050.02517.58
5.5.240.0110.02317.11
5.5.230.0000.01314.22
5.5.220.0070.00714.48
5.5.210.0000.01214.06
5.5.200.0070.00714.37
5.5.190.0030.00914.37
5.5.180.0030.00914.46
5.5.170.0120.00014.53
5.5.160.0030.00614.39
5.5.150.0030.00814.20
5.5.140.0070.00713.95
5.5.130.0070.00714.47
5.5.120.0040.00814.30
5.5.110.0060.00614.16
5.5.100.0040.00714.08
5.5.90.0040.00414.27
5.5.80.0110.00414.34
5.5.70.0070.01014.38
5.5.60.0100.00714.50
5.5.50.0080.00414.49
5.5.40.0040.01114.33
5.5.30.0110.00414.46
5.5.20.0000.01614.20
5.5.10.0060.00614.41
5.5.00.0070.00714.09
5.4.450.0420.02915.53
5.4.440.0470.02815.29
5.4.430.0220.04215.38
5.4.420.0090.03815.40
5.4.410.0380.03515.43
5.4.400.0120.03715.10
5.4.390.0110.03314.98
5.4.380.0200.02815.10
5.4.370.0150.03514.98
5.4.360.0170.03015.04
5.4.350.0220.02815.12
5.4.340.0120.03315.04
5.4.330.0060.00611.43
5.4.320.0200.02814.98
5.4.310.0150.03215.03
5.4.300.0210.02815.07
5.4.290.0200.03115.08
5.4.280.0170.03415.01
5.4.270.0200.02715.06
5.4.260.0230.02515.09
5.4.250.0180.03315.02
5.4.240.0180.03515.08
5.4.230.0180.03514.95
5.4.220.0180.02815.10
5.4.210.0150.03314.92
5.4.200.0220.02514.09
5.4.190.0250.02215.08
5.4.180.0130.03315.02
5.4.170.0210.02714.99
5.4.160.0170.03015.01
5.4.150.0180.02814.96
5.4.140.0170.02913.81
5.4.130.0130.03113.89
5.4.120.0240.02213.81
5.4.110.0220.02513.80
5.4.100.0160.03013.82
5.4.90.0220.02713.86
5.4.80.0130.03113.82
5.4.70.0120.03113.93
5.4.60.0170.02813.85
5.4.50.0210.02313.92
5.4.40.0200.03913.87
5.4.30.0290.03313.84
5.4.20.0200.03013.87
5.4.10.0150.04113.92
5.4.00.0150.03413.53
5.3.290.0370.04714.66
5.3.280.0270.07714.72
5.3.270.0230.06314.79
5.3.260.0470.05314.61
5.3.250.0400.05314.62
5.3.240.0370.05014.75
5.3.230.0330.05714.61
5.3.220.0230.06014.58
5.3.210.0270.06314.58
5.3.200.0270.05314.70
5.3.190.0430.05014.72
5.3.180.0230.05714.57
5.3.170.0330.05714.71
5.3.160.0400.05014.71
5.3.150.0270.06014.63
5.3.140.0530.06014.60
5.3.130.0400.05714.69
5.3.120.0300.05714.55
5.3.110.0370.06014.60
5.3.100.0230.06314.28
5.3.90.0370.05314.26
5.3.80.0370.04714.11
5.3.70.0200.06014.14
5.3.60.0400.04714.14
5.3.50.0230.05314.13
5.3.40.0400.04013.99
5.3.30.0300.04713.95
5.3.20.0330.04313.84
5.3.10.0330.04313.66
5.3.00.0300.05013.76
5.2.170.0200.04711.21
5.2.160.0230.04011.27
5.2.150.0270.04011.27
5.2.140.0270.04011.19
5.2.130.0270.05011.15
5.2.120.0370.03711.25
5.2.110.0230.04311.22
5.2.100.0270.04011.11
5.2.90.0230.04311.23
5.2.80.0330.03311.21
5.2.70.0200.04711.14
5.2.60.0300.04311.28
5.2.50.0230.04711.06
5.2.40.0330.04311.14
5.2.30.0230.05711.04
5.2.20.0270.04011.03
5.2.10.0230.03710.92
5.2.00.0230.05010.95
5.1.60.0170.04010.10
5.1.50.0270.04010.05
5.1.40.0200.03010.04
5.1.30.0170.03710.37
5.1.20.0230.03010.55
5.1.10.0230.03010.22
5.1.00.0170.04310.16
5.0.50.0130.0278.66
5.0.40.0030.0338.46
5.0.30.0130.0438.26
5.0.20.0130.0278.32
5.0.10.0170.0338.40
5.0.00.0100.0508.41
4.4.90.0100.0236.01
4.4.80.0100.0235.96
4.4.70.0170.0206.03
4.4.60.0070.0235.97
4.4.50.0100.0235.94
4.4.40.0100.0335.92
4.4.30.0100.0205.92
4.4.20.0130.0205.99
4.4.10.0070.0236.02
4.4.00.0070.0376.06
4.3.110.0100.0235.87
4.3.100.0200.0135.98
4.3.90.0070.0235.89
4.3.80.0100.0335.92
4.3.70.0130.0175.82
4.3.60.0130.0175.86
4.3.50.0070.0275.85
4.3.40.0100.0405.78
4.3.30.0000.0304.63
4.3.20.0070.0204.61
4.3.10.0000.0274.57
4.3.00.0030.0236.70

preferences:
51.99 ms | 400 KiB | 5 Q