3v4l.org

run code in 300+ PHP versions simultaneously
<?php $str = str_repeat("a\u{0308}bc", 500); echo '$str = ', $str, "\n"; function test($name, $test) { $t = microtime(true); for ($i = 0; $i < 1000; ++$i) { $test(); } echo sprintf('%.6f', (microtime(true) - $t)), 's ', $name, "\n"; } foreach (["a\u{0308}bc", 'abc', str_repeat("a\u{0308}bc", 20).'a'] as $suffix) { echo "\n", '$suffix = ', $suffix, "\n"; test('grapheme_strrpos', function () use ($str, $suffix) { return grapheme_strlen($str) - grapheme_strlen($suffix) === grapheme_strrpos($str, $suffix); }); test('grapheme_substr', function () use ($str, $suffix) { return $suffix === grapheme_substr($str, -grapheme_strlen($suffix)); }); test('grapheme_extract', function () use ($str, $suffix) { return $suffix === grapheme_extract($str, strlen($suffix), GRAPHEME_EXTR_MAXBYTES, -strlen($suffix)); }); }

preferences:
24.2 ms | 406 KiB | 5 Q