/SpeedTest/OrientDBRecordSpeedTest.php

https://github.com/davidino/OrientDB-PHP · PHP · 145 lines · 111 code · 9 blank · 25 comment · 11 complexity · 908df402284fa395bdff3217cb85db27 MD5 · raw file

  1. <?php
  2. /**
  3. * @author Anton Terekhov <anton@netmonsters.ru>
  4. * @copyright Copyright Anton Terekhov, NetMonsters LLC, 2011
  5. * @license https://github.com/AntonTerekhov/OrientDB-PHP/blob/master/LICENSE
  6. * @link https://github.com/AntonTerekhov/OrientDB-PHP
  7. * @package OrientDB-PHP
  8. */
  9. require_once 'OrientDB/OrientDB.php';
  10. /**
  11. * OrientDBRecord() test in OrientDB tests
  12. *
  13. * @author Anton Terekhov <anton@netmonsters.ru>
  14. * @package OrientDB-PHP
  15. * @subpackage Tests
  16. */
  17. class OrientDBRecordSpeedTest extends PHPUnit_Framework_TestCase
  18. {
  19. public function testDecodeRecordTextValue()
  20. {
  21. $runs = 10;
  22. $pwd = dirname(realpath(__FILE__));
  23. $text = file_get_contents($pwd . '/data/CharterofFundamentalRightsoftheEuropeanUnion.txt');
  24. $content = 'text:' . OrientDBRecordEncoder::encodeString($text);
  25. $timeStart = microtime(true);
  26. for ($i = 0; $i < $runs; $i++) {
  27. $record = new OrientDBRecord();
  28. $record->content = $content;
  29. $record->parse();
  30. }
  31. $timeEnd = microtime(true);
  32. $this->assertSame($text, $record->data->text);
  33. // echo $timeEnd - $timeStart;
  34. }
  35. public function testDecodeRecordFieldNames()
  36. {
  37. $runs = 10;
  38. $fieldsCnt = 100;
  39. // Prepare a document
  40. $document = array();
  41. for ($i = 0; $i < $fieldsCnt; $i++) {
  42. $document[] = sprintf('%1$s_%2$s:"%2$s"', 'fieldname', $i);
  43. }
  44. $document = implode(',', $document);
  45. $timeStart = microtime(true);
  46. for ($i = 0; $i < $runs; $i++) {
  47. $record = new OrientDBRecord();
  48. $record->content = $document;
  49. $record->parse();
  50. }
  51. $timeEnd = microtime(true);
  52. $this->assertNotEmpty($record->data);
  53. // echo $timeEnd - $timeStart;
  54. }
  55. public function testDecodeRecordBooleanValue()
  56. {
  57. $runs = 10;
  58. $fieldCnt = 100;
  59. // Prepare a document
  60. $document = array();
  61. for ($i = 0; $i < $fieldCnt; $i++) {
  62. $document[] = sprintf('%1$s:%2$s', $i, (rand(0, 1) ? 'true' : 'false'));
  63. }
  64. $document = implode(',', $document);
  65. $timeStart = microtime(true);
  66. for ($i = 0; $i < $runs; $i++) {
  67. $record = new OrientDBRecord();
  68. $record->content = $document;
  69. $record->parse();
  70. }
  71. $timeEnd = microtime(true);
  72. $this->assertNotEmpty($record->data);
  73. // echo $timeEnd - $timeStart;
  74. }
  75. public function testDecodeRecordLinkValue()
  76. {
  77. $runs = 10;
  78. $fieldCnt = 100;
  79. // Prepare a document
  80. $document = array();
  81. $rid = 100;
  82. for ($i = 0; $i < $fieldCnt; $i++) {
  83. $document[] = sprintf('%1$s:#%1$s:%2$s', $i, $rid--);
  84. }
  85. $document = implode(',', $document);
  86. $timeStart = microtime(true);
  87. for ($i = 0; $i < $runs; $i++) {
  88. $record = new OrientDBRecord();
  89. $record->content = $document;
  90. $record->parse();
  91. }
  92. $timeEnd = microtime(true);
  93. $this->assertNotEmpty($record->data);
  94. // echo $timeEnd - $timeStart;
  95. }
  96. public function testDecodeRecordNumberValue()
  97. {
  98. $runs = 10;
  99. $fieldCnt = 100;
  100. // Prepare a document
  101. $document = array();
  102. for ($i = 0; $i < $fieldCnt; $i++) {
  103. $document[] = sprintf('%1$s:%2$ff', $i, rand(-2000000, 2000000));
  104. }
  105. $document = implode(',', $document);
  106. $timeStart = microtime(true);
  107. for ($i = 0; $i < $runs; $i++) {
  108. $record = new OrientDBRecord();
  109. $record->content = $document;
  110. $record->parse();
  111. }
  112. $timeEnd = microtime(true);
  113. $this->assertNotEmpty($record->data);
  114. // echo $timeEnd - $timeStart;
  115. }
  116. public function testDecodeRecordMapValue()
  117. {
  118. $runs = 10;
  119. $fieldCnt = 100;
  120. // Prepare a document
  121. $map = array();
  122. for ($i = 0; $i < $fieldCnt; $i++) {
  123. $map[] = sprintf('"very.long.fieldname_%1$05d":%2$d', $i, rand(-2000, 2000));
  124. }
  125. $map = implode(',', $map);
  126. $timeStart = microtime(true);
  127. for ($i = 0; $i < $runs; $i++) {
  128. $record = new OrientDBRecord();
  129. $record->content = 'map:{' . $map . '}';
  130. $record->parse();
  131. }
  132. $timeEnd = microtime(true);
  133. $this->assertNotEmpty($record->data->map);
  134. // echo $timeEnd - $timeStart;
  135. }
  136. }