Skip to content

Commit

Permalink
add mtrebi
Browse files Browse the repository at this point in the history
  • Loading branch information
Fdhvdu committed Mar 31, 2019
1 parent 3933505 commit 2cfa67d
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ P.S. About [bilash/threadpool](https://github.com/bilash/threadpool), I don't wa
P.S. [nbsdx/ThreadPool](https://github.com/nbsdx/ThreadPool) cannot pass testing, see [README](comparison/nbsdx/README.md#warning).<br>
P.S. [philipphenkel/threadpool](https://github.com/philipphenkel/threadpool) cannot pass testing, see [README](comparison/philipphenkel/README.md#warning).<br>
P.S. [tghosgor/threadpool11](https://github.com/tghosgor/threadpool11) cannot pass testing, see [README](comparison/tghosgor/README.md#warning).<br>
P.S. [mtrebi/thread-pool](https://github.com/mtrebi/thread-pool) cannot pass testing, see [README](comparison/mtrebi/README.md#warning).<br>
See the [directory](comparison/) for more details.
# Compiler
Visual Studio 2017 15.5.5
Expand Down
3 changes: 2 additions & 1 deletion comparison/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ So, the function should be short, and what we need to do is test
[philipphenkel/threadpool](https://github.com/philipphenkel/threadpool) commit: bb6da2e40eacb3358e5c648f2242faf307a54268<br>
[tghosgor/threadpool11](https://github.com/tghosgor/threadpool11) commit: 8bfcf6afbdb60b2dc7976762f45fd424de06097a<br>
[Tyler-Hardin/thread_pool](https://github.com/Tyler-Hardin/thread_pool) commit: 0b1eff9817d89266232489cd250d24841e147dc3
[mtrebi/thread-pool](https://github.com/mtrebi/thread-pool) commit: f54808b60544555bd8e1b1b748009d55a657e8c1
# Environment
Motherboard: ASUS TUF X299 MARK 1<br>
CPU: Intel(R) Core(TM) i7-7820X<br>
Expand All @@ -21,7 +22,7 @@ OS: Linux 4.14.15-1-ARCH #1 SMP PREEMPT<br>
Compiler: gcc version 7.2.1 20180116<br>
boost version: 1.66.0-1
# Result
First, I will not compare nbsdx, philipphenkel and tghosgor. Because their works has potential bug.<br>
First, I will not compare nbsdx, philipphenkel, tghosgor and mtrebi. Because their works has potential bug.<br>
You can get the following statistic in their directory. (out_100000)<br>
Construct and destruct time:

Expand Down
17 changes: 17 additions & 0 deletions comparison/header/mtrebi.hpp
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
5 changes: 5 additions & 0 deletions comparison/mtrebi/README.md
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.
20 changes: 20 additions & 0 deletions comparison/mtrebi/test.cpp
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";
}
64 changes: 64 additions & 0 deletions comparison/src/mtrebi.cpp
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;
}

0 comments on commit 2cfa67d

Please sign in to comment.