3v4l.org

run code in 500+ PHP versions simultaneously
<?php /* * Run pinned to specific CPU core: * taskset -c 3 php perf-regex-strings.php */ $pattern = '/[&]/u'; // This will not produce any match in test subject. $textA = 'weengahhoghecho1eeSheeG5el9cie5b'; $textB = sprintf('%s', 'weengahhoghecho1eeSheeG5el9cie5b'); $textC = 'weengahhoghecho1eeSheeG5el9cie5' . 'b'; $textD_1 = 'weengahhoghecho1eeSheeG5el9cie5'; $textD = $textD_1 . 'b'; $tests = ['A', 'A', 'B', 'C', 'D', 'A', 'B', 'C', 'D']; foreach ($tests as $test) { $subject = ''; switch ($test) { case 'A': $subject = $textA; break; case 'B': $subject = $textB; break; case 'C': $subject = $textC; break; case 'D': $subject = $textD; break; } $start = microtime(true); for ($i = 0; $i < 1000000; $i++) { preg_match($pattern, $subject); } $diff = sprintf('%.6f sec.', microtime(true) - $start); echo "Execution time $test: $diff\n"; gc_collect_cycles(); }
Output for 8.5.11
Execution time A: 0.071503 sec. Execution time A: 0.052051 sec. Execution time B: 0.054563 sec. Execution time C: 0.052694 sec. Execution time D: 0.030555 sec. Execution time A: 0.052350 sec. Execution time B: 0.052309 sec. Execution time C: 0.052223 sec. Execution time D: 0.030175 sec.

preferences:
26.28 ms | 1136 KiB | 6 Q