-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
39 lines (30 loc) · 961 Bytes
/
Copy pathmain.cpp
File metadata and controls
39 lines (30 loc) · 961 Bytes
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
#include "thread_sequence.h"
#include "thread_pool.h"
#include "high_resolution_timer.h"
#include <chrono>
using std::chrono::duration_cast;
using std::chrono::milliseconds;
using std::chrono::high_resolution_clock;
using concurrent::high_resolution_timer;
int main(int argc, char **argv) {
auto tp = high_resolution_clock::now();
auto tp1 = high_resolution_clock::now();
auto duration = [&](decltype(tp) t){
return duration_cast<milliseconds>(high_resolution_clock::now() - t).count();
};
//#1 interval
high_resolution_timer t;
t.setInterval([&]() {
printf("%lld ms\n", duration(tp1));
tp1 = high_resolution_clock::now();
}, 1000/ 100);
//#2 timeout
t.setTimeout([&] {
printf("---%lld ms\n", duration(tp));
}, 100);
//#3 sleep
t.sleep_for(1001);
t.stop();
printf("Total: %lld ms\n", duration(tp));
return 0;
}