3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types=1); mb_internal_encoding('utf-8'); error_reporting(E_ALL); $text1 = "ну что. не смотрел еще black mesa?я собирался скачать ,но все как-то некогда было!"; $text2 = " roses are red,and violets are blue.whatever you do I'll keep it for you."; $text3 = "привет.есть 2 функции,preg_split и explode ,не понимаю,в чем между ними разница."; $text4 = "много их в Петербурге,молоденьких дур,сегодня в атласе да бархате,а завтра , поглядишь , метут улицу вместе с голью кабацкою...в самом деле ,что было бы с нами ,если бы вместо общеудобного правила:чин чина почитай , ввелось в употребление другое,например:ум ума почитай?какие возникли бы споры!"; function makeFirstCharInSentenceUpperCase(string $sentence): string { $firstChar = mb_substr($sentence, 0, 1); $remainingSentence = mb_substr($sentence, 1); $upperFirstChar = mb_strtoupper($firstChar); return $upperFirstChar . $remainingSentence; } /** * @param string $sentence * * @return string * @throws RuntimeException */ function rearrangeSpacesInSentence(string $sentence): string { $rearrangedSentence = preg_replace( ['/\s\s+/', '/\s([.,:;!?])/', '/([.,:;!?])(\w)/u'], [' ', '$1', '$1 $2'], $sentence ); if (null === $rearrangedSentence) { throw new RuntimeException(preg_last_error_msg()); } return $rearrangedSentence; } /** * @param string $text * @param array<callable(string):string> $rules * * @return string * @throws RuntimeException */ function fixSentencesInTextByRules(string $text, array $rules): string { $sentences = preg_split('/(?<=[.!?])(?=[\w\s])/u', $text, -1, PREG_SPLIT_NO_EMPTY); foreach ($rules as $rule) { $sentences = array_map($rule, $sentences); } return implode(' ', $sentences); } $texts = [$text1, $text2, $text3, $text4]; $sentenceRules = [ trim(...), makeFirstCharInSentenceUpperCase(...), rearrangeSpacesInSentence(...), ]; foreach ($texts as $text) { echo fixSentencesInTextByRules($text, $sentenceRules), "\n"; }

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.00718.81
8.4.120.0110.00920.35
8.4.110.0130.00818.22
8.4.100.0090.01218.96
8.4.90.0100.01020.57
8.4.80.0070.00818.77
8.4.70.0050.00318.05
8.4.60.0150.00720.89
8.4.50.0130.00818.32
8.4.40.0100.01020.70
8.4.30.0080.01122.33
8.4.20.0170.00317.90
8.4.10.0160.00324.17
8.3.250.0140.00618.92
8.3.240.0080.01117.18
8.3.230.0130.00716.97
8.3.220.0100.00918.96
8.3.210.0030.00517.08
8.3.200.0060.00317.15
8.3.190.0130.00620.71
8.3.180.0110.01116.62
8.3.170.0040.00418.99
8.3.160.0130.00616.95
8.3.150.0060.00318.93
8.3.140.0100.01019.18
8.3.130.0000.00818.75
8.3.120.0060.00320.86
8.3.110.0130.00322.58
8.3.100.0030.00622.58
8.3.50.0060.00322.58
8.2.290.0120.00620.46
8.2.280.0110.00819.05
8.2.270.0120.00617.07
8.2.260.0240.00516.84
8.2.250.0040.00418.77
8.2.240.0030.00719.29
8.2.230.0080.00822.58
8.2.220.0030.00622.58
8.2.70.0190.00079.33
8.2.60.0100.00630.11
8.2.50.0130.00538.15
8.2.40.0080.00838.28
8.2.30.0160.00338.28
8.2.20.0140.00438.28
8.2.10.0140.00338.10
8.2.00.0120.00438.23
8.1.330.0110.00822.21
8.1.320.0080.01216.65
8.1.310.0030.00717.05
8.1.300.0100.00718.17
8.1.200.0170.00479.33
8.1.190.0080.00938.02
8.1.180.0110.00538.11
8.1.170.0120.00538.14
8.1.160.0100.00838.06
8.1.150.0160.00338.15
8.1.140.0080.00938.06
8.1.130.0100.00638.10
8.1.120.0100.00638.11
8.1.110.0120.00438.07
8.1.100.0140.00338.06
8.1.90.0140.00238.11
8.1.80.0090.00838.03
8.1.70.0090.00838.07
8.1.60.0130.00438.27
8.1.50.0120.00638.19
8.1.40.0140.00438.22
8.1.30.0120.00638.23
8.1.20.0130.00538.19
8.1.10.0170.00138.21
8.1.00.0140.00438.03
8.0.290.0110.00479.33
8.0.280.0120.00537.53
8.0.270.0110.00437.46
8.0.260.0110.00437.57
8.0.250.0110.00437.46
8.0.240.0090.00637.46
8.0.230.0150.00137.53
8.0.220.0120.00337.49
8.0.210.0100.00637.49
8.0.200.0120.00437.46
8.0.190.0140.00337.46
8.0.180.0120.00537.57
8.0.170.0110.00437.56
8.0.160.0130.00337.57
8.0.150.0110.00637.49
8.0.140.0110.00437.46
8.0.130.0150.00137.49
8.0.120.0100.00537.46
8.0.110.0110.00437.49
8.0.100.0120.00437.53
8.0.90.0110.00537.46
8.0.80.0110.00437.49
8.0.70.0100.00637.49
8.0.60.0110.00337.63
8.0.50.0130.00337.53
8.0.30.0140.00237.46
8.0.20.0090.00637.52
8.0.10.0090.00737.46

preferences:
16.3 ms | 403 KiB | 5 Q