forked from Fdhvdu/ThreadPool
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
109 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#ifndef MTREBI | ||
#define MTREBI | ||
#include"test.hpp" | ||
|
||
//how fast can a thread pool construct and destruct (test iteration times) | ||
nTest::duration test_mtrebi_ctor_and_dtor(unsigned long cnt); | ||
|
||
//how fast can a thread pool (really) construct and (really) destruct (test iteration times) | ||
nTest::duration test_mtrebi_init_and_dtor(unsigned long cnt); | ||
|
||
//how fast can a thread pool complete N jobs, while N equals to the size of thread pool (test iteration times) | ||
nTest::duration test_mtrebi_specific_N(unsigned long cnt); | ||
|
||
//how fast can a thread pool complete iteration jobs, while the size of thread pool is thread_count or constexpr_thread_count | ||
nTest::duration test_mtrebi_job(unsigned long cnt); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Compile command | ||
g++ -std=c++14 -O3 test.cpp ../src/mtrebi.cpp -lpthread | ||
# Warning | ||
Do not use this.<br> | ||
It gets stuck when runing out_100 sometimes. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#include<fstream> | ||
#include<string> | ||
#include"../header/mtrebi.hpp" | ||
|
||
int main(int argc,char **argv) | ||
{ | ||
using namespace std; | ||
const auto cnt(stoul(argv[1])); | ||
ofstream ofs("out_"+string(argv[1])); | ||
|
||
ofs<<"mtrebi"<<endl<<"\teach spends "<< | ||
test_mtrebi_ctor_and_dtor(cnt)/cnt | ||
<<" nanoseconds on test_mtrebi_ctor_and_dtor"<<endl<<"\teach spends "<< | ||
test_mtrebi_init_and_dtor(cnt)/cnt | ||
<<" nanoseconds on test_mtrebi_init_and_dtor"<<endl<<"\teach spends "<< | ||
test_mtrebi_specific_N(cnt)/cnt | ||
<<" nanoseconds on test_mtrebi_specific_N"<<endl<<"\teach spends "<< | ||
test_mtrebi_job(cnt)/cnt | ||
<<" nanoseconds on test_mtrebi_job"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#include"../header/mtrebi.hpp" | ||
#include<future> | ||
#include<queue> | ||
#include"../../../../mtrebi/thread-pool/include/ThreadPool.h" | ||
using namespace std; | ||
|
||
nTest::duration test_mtrebi_ctor_and_dtor(unsigned long cnt) | ||
{ | ||
return nTool::calc_time([&]{ | ||
while(cnt--) | ||
ThreadPool tp(nTest::thread_count); | ||
}).duration_nanoseconds(); | ||
} | ||
|
||
nTest::duration test_mtrebi_init_and_dtor(unsigned long cnt) | ||
{ | ||
return nTool::calc_time([&]{ | ||
while(cnt--) | ||
{ | ||
ThreadPool tp(nTest::thread_count); | ||
tp.init(); | ||
tp.shutdown(); | ||
} | ||
}).duration_nanoseconds(); | ||
} | ||
|
||
nTest::duration test_mtrebi_specific_N(unsigned long cnt) | ||
{ | ||
ThreadPool tp(nTest::thread_count); | ||
tp.init(); | ||
queue<future<void>> que; | ||
const auto dur(nTool::calc_time([&]{ | ||
while(cnt--) | ||
{ | ||
for(auto i(nTest::thread_count);i--;) | ||
que.emplace(tp.submit(nTest::empty)); | ||
while(que.size()) | ||
{ | ||
que.front().get(); | ||
que.pop(); | ||
} | ||
} | ||
}).duration_nanoseconds()); | ||
tp.shutdown(); | ||
return dur; | ||
} | ||
|
||
nTest::duration test_mtrebi_job(unsigned long cnt) | ||
{ | ||
ThreadPool tp(nTest::thread_count); | ||
tp.init(); | ||
queue<future<void>> que; | ||
const auto dur(nTool::calc_time([&]{ | ||
while(cnt--) | ||
que.emplace(tp.submit(nTest::empty)); | ||
while(que.size()) | ||
{ | ||
que.front().get(); | ||
que.pop(); | ||
} | ||
}).duration_nanoseconds()); | ||
tp.shutdown(); | ||
return dur; | ||
} |