Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <chrono>
- #include "Integrator.h"
- #include "IntegratorPool.h"
- using namespace std;
- int main()
- {
- double dt = 0.1;
- vector<double> dataSet;
- for (size_t i = 0; i < 100000; i++)
- dataSet.push_back(sin(i * dt) + 1);
- {
- Integrator integrator;
- auto tstart = chrono::high_resolution_clock::now();
- for (size_t i = 0; i < 100; i++)
- {
- integrator.Start();
- integrator.Count(dataSet, dt);
- while (integrator.GetStatus() == Integrator::Status::WORKING);
- integrator.Stop();
- }
- auto tstop = chrono::high_resolution_clock::now();
- cout << "Jeden watek: " << chrono::duration_cast<chrono::milliseconds>(tstop - tstart).count() << " us" << endl;
- }
- {
- const int integrators_count = 100;
- Integrator* integrators[integrators_count];
- auto tstart = chrono::high_resolution_clock::now();
- for (size_t i = 0; i < integrators_count; i++)
- {
- integrators[i] = new Integrator();
- integrators[i]->Start();
- integrators[i]->Count(dataSet, dt);
- }
- for (size_t i = 0; i < integrators_count; i++)
- {
- while (integrators[i]->GetStatus() == Integrator::Status::WORKING);
- integrators[i]->Stop();
- delete integrators[i];
- }
- auto tstop = chrono::high_resolution_clock::now();
- cout << "Bez puli: " << chrono::duration_cast<chrono::milliseconds>(tstop - tstart).count() << " us" << endl;
- }
- {
- auto threadPool = new IntegratorPool(100);
- auto tstart = chrono::high_resolution_clock::now();
- for (size_t i = 0; i < 100; i++)
- {
- Integrator* integrator;
- while ((integrator = threadPool->GetInstance()) == nullptr);
- integrator->Count(dataSet, dt);
- }
- while (threadPool->GetLoad() > 0);
- auto tstop = chrono::high_resolution_clock::now();
- cout << "Z pulą obiektów: " << chrono::duration_cast<chrono::milliseconds>(tstop - tstart).count() << " us" << endl;
- delete threadPool;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement