MDDoIncludeViews.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. /**
  3. * @package Kohana/Codebench
  4. * @category Tests
  5. * @author Geert De Deckere <geert@idoe.be>
  6. */
  7. class Bench_MDDoIncludeViews extends Codebench {
  8. public $description =
  9. 'Optimization for the <code>doIncludeViews()</code> method of <code>Kohana_Kodoc_Markdown</code>
  10. for the Kohana Userguide.';
  11. public $loops = 10000;
  12. public $subjects = [
  13. // Valid matches
  14. '{{one}} two {{three}}',
  15. '{{userguide/examples/hello_world_error}}',
  16. // Invalid matches
  17. '{}',
  18. '{{}}',
  19. '{{userguide/examples/hello_world_error}',
  20. '{{userguide/examples/hello_world_error }}',
  21. '{{userguide/examples/{{hello_world_error }}',
  22. ];
  23. public function bench_original($subject)
  24. {
  25. preg_match_all('/{{(\S+?)}}/m', $subject, $matches, PREG_SET_ORDER);
  26. return $matches;
  27. }
  28. public function bench_possessive($subject)
  29. {
  30. // Using a possessive character class
  31. // Removed useless /m modifier
  32. preg_match_all('/{{([^\s{}]++)}}/', $subject, $matches, PREG_SET_ORDER);
  33. return $matches;
  34. }
  35. public function bench_lookaround($subject)
  36. {
  37. // Using lookaround to move $mathes[1] into $matches[0]
  38. preg_match_all('/(?<={{)[^\s{}]++(?=}})/', $subject, $matches, PREG_SET_ORDER);
  39. return $matches;
  40. }
  41. }