UserFuncArray.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. /**
  3. * @package koseven/Codebench
  4. * @category Tests
  5. * @author Woody Gilk <woody.gilk@kohanaphp.com>
  6. */
  7. class Bench_UserFuncArray extends Codebench {
  8. public $description =
  9. 'Testing the speed difference of using <code>call_user_func_array</code>
  10. compared to counting args and doing manual calls.';
  11. public $loops = 100000;
  12. public $subjects = [
  13. // Argument sets
  14. [],
  15. ['one'],
  16. ['one', 'two'],
  17. ['one', 'two', 'three'],
  18. ];
  19. public function bench_count_args($args)
  20. {
  21. $name = 'callme';
  22. switch (count($args))
  23. {
  24. case 1:
  25. $this->$name($args[0]);
  26. break;
  27. case 2:
  28. $this->$name($args[0], $args[1]);
  29. break;
  30. case 3:
  31. $this->$name($args[0], $args[1], $args[2]);
  32. break;
  33. case 4:
  34. $this->$name($args[0], $args[1], $args[2], $args[3]);
  35. break;
  36. default:
  37. call_user_func_array([$this, $name], $args);
  38. break;
  39. }
  40. }
  41. public function bench_direct_call($args)
  42. {
  43. $name = 'callme';
  44. call_user_func_array([$this, $name], $args);
  45. }
  46. protected function callme()
  47. {
  48. return count(func_get_args());
  49. }
  50. }