3v4l.org

run code in 300+ PHP versions simultaneously
<?php $str = str_repeat('abc', 1000); echo '$str = ', $str, "\n"; function test($name, $test) { $t = microtime(true); for ($i = 0; $i < 100000; ++$i) { $test(); } echo sprintf('%.6f', (microtime(true) - $t)), 's ', $name, "\n"; } foreach (['abc', 'abb', 'bbc', str_repeat('b', 100)] as $prefix) { echo "\n", '$prefix = ', $prefix, "\n"; test('strpos', function () use ($str, $prefix) { return 0 === strpos($str, $prefix); }); test('strncmp', function () use ($str, $prefix) { return 0 === strncmp($str, $prefix, strlen($prefix)); }); test('[0] + strncmp', function () use ($str, $prefix) { return $prefix[0] === $str[0] && 0 === strncmp($str, $prefix, strlen($prefix)); }); }

Abusive script

This script was stopped while abusing our resources


preferences:
23.48 ms | 408 KiB | 5 Q