hqltests.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems®.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ############################################################################## */
  13. #ifdef _USE_CPPUNIT
  14. #include "unittests.hpp"
  15. #include "hqlexpr.hpp"
  16. class ThreadedParseStressTest : public CppUnit::TestFixture
  17. {
  18. CPPUNIT_TEST_SUITE( ThreadedParseStressTest );
  19. CPPUNIT_TEST(testAllocs);
  20. CPPUNIT_TEST(testThreads);
  21. CPPUNIT_TEST_SUITE_END();
  22. void testThreads(unsigned maxParallel)
  23. {
  24. const unsigned numIter = 20000;
  25. const unsigned numFor = 50;
  26. CCycleTimer timer;
  27. class casyncfor: public CAsyncFor
  28. {
  29. public:
  30. void Do(unsigned i)
  31. {
  32. if (i & 1)
  33. {
  34. const char * query =
  35. "RECORD\n"
  36. " unsigned2 v21;\n"
  37. " unsigned2 v12;\n"
  38. " unsigned2 v8;\n"
  39. " real8 factor;\n"
  40. " END;\n";
  41. OwnedHqlExpr parsed;
  42. for (unsigned i=0; i < numIter; i++)
  43. {
  44. OwnedHqlExpr next = parseQuery(query, nullptr);
  45. }
  46. }
  47. else
  48. {
  49. for (unsigned i=0; i < numIter*2; i++)
  50. {
  51. //Allocate something the same size as CLocationAnnotation
  52. free(calloc(72, 1));
  53. /*
  54. try
  55. {
  56. SocketEndpoint ep(99);
  57. // Owned<ISocket> temp = ISocket::connect_timeout(ep, 0);
  58. Owned<ISocket> temp = ISocket::create(99);
  59. }
  60. catch (IException * e)
  61. {
  62. e->Release();
  63. }*/
  64. }
  65. }
  66. }
  67. } afor;
  68. afor.For(numFor, maxParallel, false, false);
  69. unsigned __int64 numNs = timer.elapsedNs();
  70. unsigned __int64 totalIters = numFor * numIter;
  71. printf("test %u threads took %uns each parse\n", maxParallel, (unsigned)(numNs/(totalIters)));
  72. }
  73. void testThreads()
  74. {
  75. testThreads(2);
  76. testThreads(3);
  77. testThreads(4);
  78. testThreads(8);
  79. testThreads(16);
  80. testThreads(32);
  81. }
  82. void testAllocs(unsigned maxParallel)
  83. {
  84. const unsigned numIter = 100000;
  85. CCycleTimer timer;
  86. class casyncfor: public CAsyncFor
  87. {
  88. public:
  89. void Do(unsigned i)
  90. {
  91. OwnedHqlExpr zero = createConstant(0);
  92. for (unsigned i=0; i < numIter; i++)
  93. {
  94. OwnedHqlExpr annot = createLocationAnnotation(LINK(zero), nullptr, 0, 0);
  95. }
  96. }
  97. } afor;
  98. afor.For(100, maxParallel, false, false);
  99. unsigned __int64 numNs = timer.elapsedNs();
  100. unsigned __int64 totalIters = 100 * numIter;
  101. printf("test %u threads took %uns each alloc\n", maxParallel, (unsigned)(numNs/(totalIters)));
  102. }
  103. void testAllocs()
  104. {
  105. testAllocs(2);
  106. testAllocs(3);
  107. testAllocs(4);
  108. testAllocs(8);
  109. testAllocs(16);
  110. testAllocs(32);
  111. }
  112. };
  113. CPPUNIT_TEST_SUITE_REGISTRATION( ThreadedParseStressTest );
  114. CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ThreadedParseStressTest, "ThreadedParseStressTest" );
  115. #endif // _USE_CPPUNIT