<?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(); }
You have javascript disabled. You will not be able to edit any code.