test_me.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. class PerformanceIndex
  3. {
  4. public static function measure()
  5. {
  6. $start = microtime(1);
  7. $numIterations = 5000;
  8. for ($i = 0; $i < $numIterations; ++$i) {
  9. $a = md5('abracadabra');
  10. $a = eval('md5($a);');
  11. $a = sha1($a);
  12. $group = strstr('group#foobar', '#', true);
  13. $foobar = substr('group#foobar', strlen($group) + 1);
  14. self::checkParts($group, $foobar);
  15. preg_match('{^(.*?)#(.*)$}', 'group#foobar', $matches);
  16. self::checkParts($matches[1], $matches[2]);
  17. $parts = explode('#', 'group#foobar');
  18. self::checkParts($parts[0], $parts[1]);
  19. self::euler(20, 10);
  20. self::euler(2166, 6099);
  21. self::euler(1239432166, 2221248099);
  22. }
  23. return (microtime(1) - $start) / $numIterations;
  24. }
  25. private static function euler($x, $y)
  26. {
  27. $r = $x % $y;
  28. if ($r == 0) {
  29. return $y;
  30. }
  31. return self::euler($y, $r);
  32. }
  33. private static function checkParts($group, $foobar)
  34. {
  35. return $group === 'group' && $foobar === 'foobar';
  36. }
  37. }
  38. echo 'Performance index: ', PerformanceIndex::measure(), "\n";