PersisterPerformanceTest.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. namespace Doctrine\Tests\ORM\Performance;
  3. use Doctrine\ORM\Tools\SchemaTool;
  4. use Doctrine\ORM\Query;
  5. use Doctrine\Tests\Models\CMS\CmsUser;
  6. use Doctrine\Tests\Models\CMS\CmsPhonenumber;
  7. use Doctrine\Tests\Models\CMS\CmsAddress;
  8. use Doctrine\Tests\Models\CMS\CmsGroup;
  9. use Doctrine\Tests\Models\CMS\CmsArticle;
  10. use Doctrine\Tests\Models\CMS\CmsComment;
  11. require_once __DIR__ . '/../../TestInit.php';
  12. /**
  13. * @group performance
  14. */
  15. class PersisterPerformanceTest extends \Doctrine\Tests\OrmFunctionalTestCase
  16. {
  17. protected function setUp()
  18. {
  19. $this->useModelSet('cms');
  20. parent::setUp();
  21. }
  22. public function testFindCmsArticle()
  23. {
  24. $author = new CmsUser();
  25. $author->name = "beberlei";
  26. $author->status = "active";
  27. $author->username = "beberlei";
  28. $this->_em->persist($author);
  29. $ids = array();
  30. for ($i = 0; $i < 100; $i++) {
  31. $article = new CmsArticle();
  32. $article->text = "foo";
  33. $article->topic = "bar";
  34. $article->user = $author;
  35. $this->_em->persist($article);
  36. $ids[] = $article;
  37. }
  38. $this->_em->flush();
  39. $this->_em->clear();
  40. $start = microtime(true);
  41. $articles = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsArticle')->findAll();
  42. echo "100 CmsArticle findAll(): " . number_format(microtime(true) - $start, 6) . "\n";
  43. $this->_em->clear();
  44. $start = microtime(true);
  45. $articles = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsArticle')->findAll();
  46. echo "100 CmsArticle findAll(): " . number_format(microtime(true) - $start, 6) . "\n";
  47. $this->_em->clear();
  48. $start = microtime(true);
  49. for ($i = 0; $i < 100; $i++) {
  50. $articles = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsArticle')->find($ids[$i]->id);
  51. }
  52. echo "100 CmsArticle find(): " . number_format(microtime(true) - $start, 6) . "\n";
  53. $this->_em->clear();
  54. $start = microtime(true);
  55. for ($i = 0; $i < 100; $i++) {
  56. $articles = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsArticle')->find($ids[$i]->id);
  57. }
  58. echo "100 CmsArticle find(): " . number_format(microtime(true) - $start, 6) . "\n";
  59. }
  60. public function testFindCmsGroup()
  61. {
  62. for ($i = 0; $i < 100; $i++) {
  63. $group = new CmsGroup();
  64. $group->name = "foo" . $i;
  65. $this->_em->persist($group);
  66. }
  67. $this->_em->flush();
  68. $this->_em->clear();
  69. $start = microtime(true);
  70. $articles = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsGroup')->findAll();
  71. echo "100 CmsGroup: " . number_format(microtime(true) - $start, 6) . "\n";
  72. $this->_em->clear();
  73. $start = microtime(true);
  74. $articles = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsGroup')->findAll();
  75. echo "100 CmsGroup: " . number_format(microtime(true) - $start, 6) . "\n";
  76. }
  77. public function testFindCmsUser()
  78. {
  79. for ($i = 0; $i < 100; $i++) {
  80. $user = new CmsUser();
  81. $user->name = "beberlei";
  82. $user->status = "active";
  83. $user->username = "beberlei".$i;
  84. $this->_em->persist($user);
  85. }
  86. $this->_em->flush();
  87. $this->_em->clear();
  88. $start = microtime(true);
  89. $articles = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser')->findAll();
  90. echo "100 CmsUser: " . number_format(microtime(true) - $start, 6) . "\n";
  91. $this->_em->clear();
  92. $start = microtime(true);
  93. $articles = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser')->findAll();
  94. echo "100 CmsUser: " . number_format(microtime(true) - $start, 6) . "\n";
  95. }
  96. }