Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <atomic>
- #define WORKLOAD (500000)
- class Work
- {
- public:
- int DataA[WORKLOAD];
- int DataB[WORKLOAD];
- int DataC[WORKLOAD];
- std::atomic<size_t> Updates = 0;
- Work()
- {
- for (int i = 0; i < WORKLOAD; ++i)
- {
- DataA[i] = 10;
- DataB[i] = 10;
- DataC[i] = 10;
- }
- }
- void Do()
- {
- for (int i = 0; i < WORKLOAD; ++i)
- {
- DataC[i] = DataC[i] + DataA[i] + DataB[i];
- }
- Updates.fetch_add(1);
- }
- };
- bool Run = true;
- #define T_CNT (1)
- ThreadPool Threads;
- Work WorkObj;
- void WorkerFunction()
- {
- ThreadPool::Progress LocalProgress = 0;
- while (Run)
- {
- WorkObj.Do();
- Threads.Sync(LocalProgress);
- WorkObj.Do();
- Threads.Sync(LocalProgress);
- }
- }
- int main()
- {
- //Test einstellen
- int UseThreads = 4;
- int TestTime = 50;
- int TestLoops = 100;
- printf("testing... need %i ms\n", TestLoops* TestTime);
- //threads starten
- Threads.Start<std::function<void()>>([&](){ WorkerFunction(); }, UseThreads);
- //schenllsten finden
- WorkObj.Updates = 0;
- int MaxUpdate = 0;
- while (TestLoops > 0)
- {
- --TestLoops;
- Sleep(TestTime);
- if (WorlObj.Updates > MaxUpdate)
- MaxUpdate = WorlObj.Updates;
- WorlObj.Updates = 0;
- }
- //ausgabe
- printf("MaxUpdate: %i\n", MaxUpdate);
- //beenden
- Run = false;
- Threads.Join();
- std::getchar();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement