3v4l.org

run code in 300+ PHP versions simultaneously
<?php error_reporting(E_ALL); mb_internal_encoding('UTF-8'); $text1 = "Кажется, нас обнаружили! Надо срочно уходить отсюда, пока не поздно. Бежим же скорее!"; $text2 = "Ну, прости меня! Не хотела я тебе зла сделать; да в себе не вольна была. Что говорила, что делала, себя не помнила."; $text3 = "Идет гражданская война. Космические корабли повстанцев, наносящие удар с тайной базы, одержали первую победу, в схватке со зловещей Галактической Империей."; function makeFirstCharLowerCase(string $word): string { return mb_strtolower(mb_substr($word, 0, 1)) . mb_substr($word, 1); } function makeFirstCharUpperCase(string $word): string { return mb_strtoupper(mb_substr($word, 0, 1)) . mb_substr($word, 1); } /** * @return array<string> * @throws Exception */ function splitTextToSentences(string $text): array { $sentences = preg_split('/[.!?]/', $text, -1, PREG_SPLIT_NO_EMPTY); if (false === $sentences) { throw new Exception(preg_last_error_msg()); } return $sentences; } /** * @return array<string> * @throws Exception */ function splitSentenceToWords(string $sentence): array { $words = preg_split('/[-,;:\s]/', $sentence, -1, PREG_SPLIT_NO_EMPTY); if (false === $words) { throw new Exception(preg_last_error_msg()); } return $words; } /** * @param array<string> $words * @return array<string> */ function reverseWords(array $words): array { return array_reverse($words); } /** * @throws Exception */ function makeTextInYodaStyle(string $text): string { $sentences = splitTextToSentences($text); $result = ''; foreach ($sentences as $sentence) { $words = splitSentenceToWords($sentence); $reversedWords = reverseWords($words); $reversedWords[0] = makeFirstCharUpperCase($reversedWords[0]); $reversedWords[count($reversedWords) - 1] = makeFirstCharLowerCase($reversedWords[count($reversedWords) - 1]); $result .= implode(' ', $reversedWords) . '. '; } return $result; } $texts = [$text1, $text2, $text3]; $yodaText = ''; try { foreach ($texts as $text) { $yodaText = makeTextInYodaStyle($text); echo "Йода говорит: $yodaText\n"; } } catch (Exception $e) { echo "Произошла ошибка: " . $e->getMessage(); }

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.4.130.0130.00817.90
8.4.120.0120.00920.46
8.4.110.0130.00822.33
8.4.100.0110.00718.09
8.4.90.0130.00918.82
8.4.80.0060.00918.18
8.4.70.0110.00918.00
8.4.60.0060.00320.76
8.4.50.0120.00819.72
8.4.40.0070.01419.70
8.4.30.0060.01320.78
8.4.20.0150.00619.76
8.4.10.0030.00623.85
8.3.250.0110.00819.05
8.3.240.0090.01116.53
8.3.230.0070.00916.93
8.3.220.0110.00717.61
8.3.210.0060.00217.06
8.3.200.0100.00916.79
8.3.190.0120.00417.50
8.3.180.0090.01016.44
8.3.170.0000.01818.83
8.3.160.0130.00617.02
8.3.150.0120.00617.11
8.3.140.0110.00419.14
8.3.130.0060.00318.53
8.3.120.0060.00319.08
8.3.110.0080.00016.84
8.3.100.0040.00417.15
8.3.90.0000.00826.77
8.3.80.0090.00018.68
8.3.70.0170.00316.63
8.3.60.0120.00918.65
8.3.50.0150.00317.06
8.3.40.0090.00622.16
8.3.30.0040.01120.38
8.3.20.0050.00324.18
8.3.10.0090.00024.66
8.3.00.0040.00426.16
8.2.290.0060.00620.72
8.2.280.0040.00418.80
8.2.270.0070.01117.66
8.2.260.0030.00618.94
8.2.250.0040.00418.58
8.2.240.0040.00418.41
8.2.230.0060.01220.94
8.2.220.0000.01224.06
8.2.210.0080.00026.77
8.2.200.0100.00018.30
8.2.190.0080.00816.63
8.2.180.0150.00017.13
8.2.170.0180.00019.16
8.2.160.0090.00622.96
8.2.150.0080.00025.66
8.2.140.0000.00824.66
8.2.130.0080.00026.16
8.2.120.0040.00419.79
8.2.110.0100.00022.09
8.2.100.0060.00617.94
8.2.90.0050.00318.16
8.2.80.0050.00319.45
8.2.70.0120.00917.50
8.2.60.0110.00917.63
8.2.50.0070.01417.38
8.2.40.0120.00817.75
8.2.30.0110.00717.74
8.2.20.0110.00917.75
8.2.10.0150.00417.75
8.2.00.0160.00017.75
8.1.330.0140.00522.24
8.1.320.0140.00516.22
8.1.310.0110.00716.75
8.1.300.0090.00620.00
8.1.290.0000.00918.88
8.1.280.0070.00725.92
8.1.270.0050.00324.66
8.1.260.0000.00826.35
8.1.250.0030.00528.09
8.1.240.0090.00023.96
8.1.230.0090.00319.10
8.1.220.0040.00417.91
8.1.210.0050.00318.85
8.1.200.0090.00017.63
8.1.190.0130.00817.50
8.1.180.0170.00417.48
8.1.170.0190.00017.50
8.1.160.0170.00317.50
8.1.150.0150.00417.63
8.1.140.0130.00317.38
8.1.130.0140.00517.48
8.1.120.0150.00917.34
8.1.110.0190.00017.60
8.1.100.0060.01317.61
8.1.90.0110.00717.25
8.1.80.0140.00317.50
8.1.70.0120.00517.50
8.1.60.0100.01017.85
8.1.50.0160.00417.38
8.1.40.0100.01017.50
8.1.30.0130.00717.75
8.1.20.0160.00517.60
8.1.10.0180.00317.84
8.1.00.0220.00017.63
8.0.300.0040.00421.85
8.0.290.0170.00317.00
8.0.280.0130.00416.88
8.0.270.0110.00616.88
8.0.260.0120.00616.75
8.0.250.0160.00316.73
8.0.240.0130.00816.75
8.0.230.0070.01116.88
8.0.220.0120.00516.74
8.0.210.0190.00016.73
8.0.200.0120.00617.00
8.0.190.0140.00516.88
8.0.180.0200.00016.63
8.0.170.0110.00716.74
8.0.160.0000.01816.88
8.0.150.0180.00016.84
8.0.140.0080.01216.98
8.0.130.0120.00616.88
8.0.120.0150.00316.75
8.0.110.0210.00016.73
8.0.100.0140.00716.75
8.0.90.0170.00016.62
8.0.80.0040.01316.71
8.0.70.0190.00016.88
8.0.60.0150.00316.87
8.0.50.0140.00316.75
8.0.30.0100.01016.63
8.0.20.0170.00016.63
8.0.10.0150.00316.88

preferences:
68.62 ms | 403 KiB | 5 Q