ExtractPriorityQueue.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. /**
  3. * Zend Framework (http://framework.zend.com/)
  4. *
  5. * @link http://github.com/zendframework/zf2 for the canonical source repository
  6. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  7. * @license http://framework.zend.com/license/new-bsd New BSD License
  8. */
  9. namespace ZendBench\Stdlib;
  10. use Athletic\AthleticEvent;
  11. use Zend\Stdlib\FastPriorityQueue;
  12. use Zend\Stdlib\PriorityQueue;
  13. use Zend\Stdlib\SplPriorityQueue;
  14. class ExtractPriorityQueue extends AthleticEvent
  15. {
  16. public function classSetUp()
  17. {
  18. $this->splPriorityQueue = new SplPriorityQueue();
  19. $this->fastPriorityQueue = new FastPriorityQueue();
  20. $this->priorityQueue = new PriorityQueue();
  21. for ($i = 0; $i < 5000; $i += 1) {
  22. $priority = rand(1, 100);
  23. $this->splPriorityQueue->insert('foo', $priority);
  24. $this->fastPriorityQueue->insert('foo', $priority);
  25. $this->priorityQueue->insert('foo', $priority);
  26. }
  27. }
  28. /**
  29. * @iterations 5000
  30. */
  31. public function extractSplPriorityQueue()
  32. {
  33. $this->splPriorityQueue->extract();
  34. }
  35. /**
  36. * @iterations 5000
  37. */
  38. public function extractPriorityQueue()
  39. {
  40. $this->priorityQueue->extract();
  41. }
  42. /**
  43. * @iterations 5000
  44. */
  45. public function extractFastPriorityQueue()
  46. {
  47. $this->fastPriorityQueue->extract();
  48. }
  49. }