3v4l.org

run code in 300+ PHP versions simultaneously
<?php $text = "Rocket abc bla blub bla Rocket"; class CountWordSimas { /* * @param string $text */ public function countWordSort($text) { $textArray = explode(" ", $text); $wordCountArray = $this->countWords($textArray); $sortedArray = $this->sortAndReverseArray($wordCountArray); $this->printWordsCount($sortedArray); } /* * Sort the array and reverse * @return array The array sorted and reversed */ protected function sortAndReverseArray($array) { natcasesort($array); $reversedArray = $this->reverseArray($array); krsort($reversedArray); return $reversedArray; } /* * Count how many time the word appear in the array * @param array $textArray * @return array */ protected function countWords($textArray) { $wordCountArray = []; foreach ($textArray as $word) { if (!isset($wordCountArray[$word])) { $wordCountArray[$word] = 1; } else { $wordCountArray[$word]++; } } return $wordCountArray; } /* * @param array $arrayToReverse * @return array The reversed array */ protected function reverseArray($arrayToReverse) { $reversedArray = []; foreach ($arrayToReverse as $key => $value) { $reversedArray[$value][] = $key; } return $reversedArray; } /* * Print the array of words with the count value * @param array $wordsCountArray */ protected function printWordsCount($wordsCountArray) { foreach ($wordsCountArray as $count => $words) { foreach ($words as $word) { echo $count . " x " . $word; echo PHP_EOL; } } } } $simas = new CountWordSimas(); $simas->countWordSort($text);

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.0060.00918.48
8.3.50.0070.00721.98
8.3.40.0070.00718.82
8.3.30.0140.00319.22
8.3.20.0000.00720.29
8.3.10.0000.00923.70
8.3.00.0040.00419.38
8.2.180.0120.00318.54
8.2.170.0060.01222.96
8.2.160.0100.01020.39
8.2.150.0040.00424.18
8.2.140.0080.00024.66
8.2.130.0040.00426.16
8.2.120.0000.00722.31
8.2.110.0060.00322.20
8.2.100.0090.00317.91
8.2.90.0060.00317.88
8.2.80.0050.00319.11
8.2.70.0040.00418.05
8.2.60.0000.00818.05
8.2.50.0060.00318.10
8.2.40.0080.00022.21
8.2.30.0040.00418.14
8.2.20.0040.00417.77
8.2.10.0030.00518.20
8.2.00.0100.00017.83
8.1.280.0070.01125.92
8.1.270.0080.00023.96
8.1.260.0000.00826.35
8.1.250.0050.00328.09
8.1.240.0090.00023.88
8.1.230.0040.00819.09
8.1.220.0000.00917.74
8.1.210.0060.00318.77
8.1.200.0160.00717.13
8.1.190.0080.00017.11
8.1.180.0040.00418.10
8.1.170.0090.00018.59
8.1.160.0000.00721.91
8.1.150.0000.00818.54
8.1.140.0030.00517.53
8.1.130.0000.00717.85
8.1.120.0070.00017.40
8.1.110.0050.00217.46
8.1.100.0000.00717.52
8.1.90.0000.00717.52
8.1.80.0070.00017.54
8.1.70.0030.00317.37
8.1.60.0000.00817.54
8.1.50.0000.00817.46
8.1.40.0030.00517.57
8.1.30.0040.00417.58
8.1.20.0000.00817.60
8.1.10.0050.00217.55
8.1.00.0080.00017.52
8.0.300.0040.00419.60
8.0.290.0040.00416.75
8.0.280.0000.00718.42
8.0.270.0030.00317.29
8.0.260.0060.00017.33
8.0.250.0030.00317.03
8.0.240.0070.00017.01
8.0.230.0030.00316.92
8.0.220.0040.00417.00
8.0.210.0000.00716.87
8.0.200.0030.00316.89
8.0.190.0060.00316.89
8.0.180.0040.00416.95
8.0.170.0050.00316.94
8.0.160.0030.00516.96
8.0.150.0040.00416.83
8.0.140.0030.00516.78
8.0.130.0000.00613.38
8.0.120.0040.00416.76
8.0.110.0040.00416.87
8.0.100.0000.00716.76
8.0.90.0040.00416.92
8.0.80.0100.01116.79
8.0.70.0050.00216.95
8.0.60.0050.00316.94
8.0.50.0030.00516.75
8.0.30.0080.01017.20
8.0.20.0080.01317.40
8.0.10.0050.00216.92
8.0.00.0050.01516.93
7.4.330.0050.00015.00
7.4.320.0070.00016.60
7.4.300.0030.00616.53
7.4.290.0050.00316.53
7.4.280.0000.00816.59
7.4.270.0040.00416.66
7.4.260.0000.00716.48
7.4.250.0040.00416.48
7.4.240.0000.00716.50
7.4.230.0000.00716.60
7.4.220.0110.00716.71
7.4.210.0050.01016.61
7.4.200.0030.00316.29
7.4.190.0080.00016.69
7.4.160.0160.00016.49
7.4.150.0060.01217.40
7.4.140.0020.01517.86
7.4.130.0100.01216.49
7.4.120.0080.00816.54
7.4.110.0040.01416.49
7.4.100.0090.00916.53
7.4.90.0100.00716.70
7.4.80.0120.00719.39
7.4.70.0080.00916.53
7.4.60.0030.01016.40
7.4.50.0050.00316.55
7.4.40.0080.01216.38
7.4.30.0110.00416.56
7.4.00.0070.00715.04
7.3.330.0020.00213.41
7.3.320.0000.00613.39
7.3.310.0000.00716.28
7.3.300.0000.00716.44
7.3.290.0050.00916.38
7.3.280.0120.00516.41
7.3.270.0030.01417.40
7.3.260.0090.00916.61
7.3.250.0100.00816.42
7.3.240.0180.00616.41
7.3.230.0070.01416.61
7.3.210.0070.01016.66
7.3.200.0150.00319.39
7.3.190.0170.00616.45
7.3.180.0160.00316.46
7.3.170.0100.01016.40
7.3.160.0050.01116.38
7.3.120.0080.00814.54
7.2.330.0120.01216.67
7.2.320.0080.01116.83
7.2.310.0090.00816.82
7.2.300.0060.00916.65
7.2.290.0150.00316.90
7.2.60.0070.01016.97
7.2.00.0040.01419.48
7.1.200.0070.00715.91
7.1.100.0030.00818.13
7.1.70.0030.00517.01
7.1.60.0000.02219.46
7.1.50.0100.01016.70
7.1.00.0070.07322.36
7.0.200.0000.00816.64
7.0.140.0030.07322.14
7.0.60.0100.06319.88
7.0.50.0070.04017.88
7.0.40.0030.04317.72
7.0.30.0030.06717.75
7.0.20.0100.07017.79
7.0.10.0070.05017.73
7.0.00.0000.09317.73
5.6.280.0070.06720.79
5.6.210.0030.08720.50
5.6.200.0030.09318.29
5.6.190.0070.04718.17
5.6.180.0030.05718.18
5.6.170.0030.06018.22
5.6.160.0070.08318.18
5.6.150.0100.07318.28
5.6.140.0030.06018.19
5.6.130.0000.08718.30
5.6.120.0030.08718.29
5.6.110.0030.08018.14
5.6.100.0030.07718.14
5.6.90.0070.08318.14
5.6.80.0100.08017.64
5.6.70.0100.06717.53
5.6.60.0070.03717.56
5.6.50.0100.05717.56
5.6.40.0030.08017.64
5.6.30.0070.04717.53
5.6.20.0130.08017.51
5.6.10.0070.05717.51
5.6.00.0100.07017.63
5.5.350.3030.03320.45
5.5.340.0100.04718.02
5.5.330.0030.08317.99
5.5.320.0030.08318.04
5.5.310.0170.07018.04
5.5.300.0000.06317.93
5.5.290.0070.07718.09
5.5.280.0100.03718.02
5.5.270.0030.08717.96
5.5.260.0000.07318.04
5.5.250.0030.05317.80
5.5.240.0130.06017.43
5.5.230.0070.05017.30
5.5.220.0100.04017.36
5.5.210.0070.07717.31
5.5.200.0070.03717.37
5.5.190.0100.06017.29
5.5.180.0100.06017.42
5.5.160.0100.04717.30
5.5.150.0100.06017.29
5.5.140.0070.07317.33
5.5.130.0130.07317.39
5.5.120.0030.06317.36
5.5.110.0030.04717.29
5.5.100.0070.07717.27
5.5.90.0030.07017.20
5.5.80.0130.07317.34
5.5.70.0130.06017.21
5.5.60.0130.07017.23
5.5.50.0130.03017.23
5.5.40.0000.04717.18
5.5.30.0100.07317.19
5.5.20.0070.05017.32
5.5.10.0070.07317.30
5.5.00.0130.06317.17
5.4.450.0070.06019.46
5.4.440.0100.05019.47
5.4.430.0130.06019.31
5.4.420.0130.07319.45
5.4.410.0170.06019.23
5.4.400.0030.07319.04
5.4.390.0030.04719.00
5.4.380.0070.04018.98
5.4.370.0130.06719.09
5.4.360.0070.05719.27
5.4.350.0030.06019.13
5.4.340.0070.03718.89
5.4.320.0030.05319.11
5.4.310.0070.05019.02
5.4.300.0070.05319.04
5.4.290.0030.07719.05
5.4.280.0130.07019.05
5.4.270.0030.04019.26
5.4.260.0070.03719.04
5.4.250.0100.05019.01
5.4.240.0100.08019.13
5.4.230.0070.05318.94
5.4.220.0070.07018.88
5.4.210.0100.04319.13
5.4.200.0170.06719.11
5.4.190.0100.04718.88
5.4.180.0030.04718.97
5.4.170.0070.07719.00
5.4.160.0130.05319.03
5.4.150.0130.06319.11
5.4.140.0000.08316.43
5.4.130.0030.07716.57
5.4.120.0100.07016.39
5.4.110.0030.07716.39
5.4.100.0030.05716.35
5.4.90.0030.08016.46
5.4.80.0070.05316.39
5.4.70.0000.07716.32
5.4.60.0070.07016.43
5.4.50.0100.07016.38
5.4.40.0070.07016.27
5.4.30.0000.07716.30
5.4.20.0100.04716.39
5.4.10.0000.08016.37
5.4.00.0070.07315.84
5.3.290.0030.07714.63
5.3.280.0000.05714.81
5.3.270.0130.04014.68
5.3.260.0100.03314.69
5.3.250.0130.07314.66
5.3.240.0070.07714.64
5.3.230.0130.07014.57
5.3.220.0170.06014.56
5.3.210.0130.06314.63
5.3.200.0100.07014.62
5.3.190.0070.07714.60
5.3.180.0030.06314.66
5.3.170.0070.07314.59
5.3.160.0070.07014.63
5.3.150.0070.07314.42
5.3.140.0130.06314.52
5.3.130.0200.05714.59
5.3.120.0130.06714.51
5.3.110.0100.07714.40
5.3.100.0100.07314.26
5.3.90.0070.06714.06
5.3.80.0030.07314.07
5.3.70.0130.07314.23
5.3.60.0070.07014.00
5.3.50.0130.06314.00
5.3.40.0070.07314.03
5.3.30.0030.07313.96
5.3.20.0100.04013.59
5.3.10.0170.05313.73
5.3.00.0000.05313.69
5.2.170.0130.05711.37
5.2.160.0030.06311.19
5.2.150.0030.03711.23
5.2.140.0000.03711.05
5.2.130.0030.04311.07
5.2.120.0000.05011.01
5.2.110.0070.06011.11
5.2.100.0000.03311.15
5.2.90.0170.05011.07
5.2.80.0100.04010.99
5.2.70.0000.04711.08
5.2.60.0130.02011.09
5.2.50.0000.04711.07
5.2.40.0030.05711.05
5.2.30.0100.03011.07
5.2.20.0030.04310.99
5.2.10.0070.04310.88
5.2.00.0070.03310.73
5.1.60.0070.03010.00
5.1.50.0070.0509.98
5.1.40.0030.03310.02
5.1.30.0070.03310.32
5.1.20.0070.05310.36
5.1.10.0000.05010.16
5.1.00.0070.04010.07
5.0.50.0000.0238.60
5.0.40.0070.0438.44
5.0.30.0070.0608.44
5.0.20.0000.0338.44
5.0.10.0070.0438.44
5.0.00.0030.0578.44
4.4.90.0030.0138.44
4.4.80.0030.0278.44
4.4.70.0030.0178.44
4.4.60.0030.0138.44
4.4.50.0070.0108.44
4.4.40.0070.0508.44
4.4.30.0030.0238.44
4.4.20.0000.0338.44
4.4.10.0000.0378.44
4.4.00.0070.0338.44
4.3.110.0030.0308.44
4.3.100.0030.0178.44
4.3.90.0070.0338.44
4.3.80.0000.0608.44
4.3.70.0000.0308.44
4.3.60.0070.0208.44
4.3.50.0070.0208.44
4.3.40.0000.0278.44
4.3.30.0070.0238.44
4.3.20.0000.0408.44
4.3.10.0030.0378.44
4.3.00.0030.0378.44

preferences:
41.32 ms | 400 KiB | 5 Q