FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
cpp-taskflow/benchmarks/thread_pool/thread_pool.cpp at master · ezhangle/cpp-taskflow · GitHub
ezhangle
/
cpp-taskflow
Public
forked from
taskflow/taskflow
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
cpp-taskflow
/
benchmarks
/
thread_pool
/
thread_pool.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
82 lines (74 loc) · 1.84 KB
Breadcrumbs
cpp-taskflow
/
benchmarks
/
thread_pool
/
thread_pool.cpp
Copy path
File metadata and controls
82 lines (74 loc) · 1.84 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#
include
<
taskflow/taskflow.hpp
>
#
include
"
ThreadPool.hpp
"
ThreadPool* ThreadPool::singleton =
nullptr
;
std::mutex ThreadPool::singleton_mutex;
tf::Executor executor;
class
ChronoTimer
{
public:
ChronoTimer
(
void
) {
}
void
start
(
void
){
startTime =
std::chrono::high_resolution_clock::now
();
}
void
finish
(std::string msg){
auto
finish =
std::chrono::high_resolution_clock::now
();
std::chrono::duration<
double
> elapsed = finish - startTime;
printf
(
"
%s : %f ms
\n
"
,msg.
c_str
(), elapsed.
count
() *
1000
);
}
private:
std::chrono::high_resolution_clock::time_point startTime;
};
float
benchFunc
(
uint64_t
loopLen){
float
acc =
0
;
for
(
uint64_t
k =
0
; k < loopLen; ++k)
acc += k;
return
acc;
}
void
bench
(
uint32_t
iter){
printf
(
"
Benchmark with %d iterations
\n
"
,iter);
const
uint64_t
num_blocks =
1000
;
const
uint64_t
loopLen =
100
;
ChronoTimer timer;
ThreadPool *pool =
ThreadPool::get
();
timer.
start
();
for
(
uint64_t
it =
0
; it < iter; ++it) {
tf::Taskflow taskflow;
tf::Task node[num_blocks];
for
(
uint64_t
i =
0
; i < num_blocks; i++)
node[i] = taskflow.
placeholder
();
for
(
uint64_t
i =
0
; i < num_blocks; i++) {
node[i].
work
([=]() {
benchFunc
(loopLen);
});
}
executor.
run
(taskflow).
wait
();
}
timer.
finish
(
"
taskflow: time in ms:
"
);
timer.
start
();
for
(
uint64_t
it =
0
; it < iter; ++it) {
std::vector<std::future<
int
>> results;
for
(
uint64_t
i =
0
; i < num_blocks; i++) {
results.
emplace_back
(pool->
enqueue
([=]() {
benchFunc
(loopLen);
return
0
;
}));
}
for
(
auto
& result : results)
{
result.
get
();
}
}
timer.
finish
(
"
threadpool: time in ms:
"
);
}
int
main
() {
for
(
uint32_t
i =
0
; i <
5
; ++i)
bench
(
100
);
for
(
uint32_t
i =
0
; i <
5
; ++i)
bench
(
50
);
for
(
uint32_t
i =
0
; i <
5
; ++i)
bench
(
20
);
for
(
uint32_t
i =
0
; i <
5
; ++i)
bench
(
10
);
for
(
uint32_t
i =
0
; i <
5
; ++i)
bench
(
5
);
}
Back
|
FazBrowse Home
|
New Git URL