Advertisement
Guest User

12312

a guest
Dec 10th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <chrono>
  4. #include "Integrator.h"
  5. #include "IntegratorPool.h"
  6.  
  7. using namespace std;
  8.  
  9. int main()
  10. {
  11. double dt = 0.1;
  12. vector<double> dataSet;
  13.  
  14. for (size_t i = 0; i < 100000; i++)
  15. dataSet.push_back(sin(i * dt) + 1);
  16.  
  17. {
  18. Integrator integrator;
  19. auto tstart = chrono::high_resolution_clock::now();
  20. for (size_t i = 0; i < 100; i++)
  21. {
  22. integrator.Start();
  23. integrator.Count(dataSet, dt);
  24. while (integrator.GetStatus() == Integrator::Status::WORKING);
  25. integrator.Stop();
  26. }
  27.  
  28. auto tstop = chrono::high_resolution_clock::now();
  29. cout << "Jeden watek: " << chrono::duration_cast<chrono::milliseconds>(tstop - tstart).count() << " us" << endl;
  30. }
  31. {
  32.  
  33. const int integrators_count = 100;
  34. Integrator* integrators[integrators_count];
  35. auto tstart = chrono::high_resolution_clock::now();
  36.  
  37. for (size_t i = 0; i < integrators_count; i++)
  38. {
  39. integrators[i] = new Integrator();
  40. integrators[i]->Start();
  41. integrators[i]->Count(dataSet, dt);
  42. }
  43.  
  44. for (size_t i = 0; i < integrators_count; i++)
  45. {
  46. while (integrators[i]->GetStatus() == Integrator::Status::WORKING);
  47. integrators[i]->Stop();
  48. delete integrators[i];
  49. }
  50.  
  51. auto tstop = chrono::high_resolution_clock::now();
  52. cout << "Bez puli: " << chrono::duration_cast<chrono::milliseconds>(tstop - tstart).count() << " us" << endl;
  53. }
  54.  
  55. {
  56. auto threadPool = new IntegratorPool(100);
  57.  
  58. auto tstart = chrono::high_resolution_clock::now();
  59.  
  60. for (size_t i = 0; i < 100; i++)
  61. {
  62. Integrator* integrator;
  63. while ((integrator = threadPool->GetInstance()) == nullptr);
  64. integrator->Count(dataSet, dt);
  65. }
  66.  
  67. while (threadPool->GetLoad() > 0);
  68.  
  69. auto tstop = chrono::high_resolution_clock::now();
  70. cout << "Z pulą obiektów: " << chrono::duration_cast<chrono::milliseconds>(tstop - tstart).count() << " us" << endl;
  71.  
  72. delete threadPool;
  73. }
  74.  
  75.  
  76.  
  77.  
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement