-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathexamples.cpp
112 lines (98 loc) · 1.95 KB
/
examples.cpp
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include <algorithm>
#include <numeric>
#include <set>
#include <unistd.h>
#include <vector>
#include "tqdm.hpp"
const int sleep_time = 200;
std::vector<int> get_vector(int size)
{
std::vector<int> A(size);
std::iota(A.begin(), A.end(), 1000);
// std::generate(A.begin(), A.end(), []() {return rand(); } );
return A;
}
std::set<int> get_set(int size)
{
std::vector<int> A(size);
std::iota(A.begin(), A.end(), 1000);
// std::generate(A.begin(), A.end(), []() {return rand(); } );
return std::set<int>(A.begin(), A.end());
}
void test_rvalue()
{
auto T = tq::tqdm(get_vector(5000));
T.set_prefix("tqdm from rvalue ");
for (auto t : T)
{
usleep(sleep_time);
T << t;
}
}
void test_lvalue()
{
auto A = get_vector(5000);
auto T = tq::tqdm(A);
T.set_prefix("tqdm from lvalue ");
for (auto&& t : T)
{
t *= 2;
usleep(sleep_time);
T << t;
}
}
void test_lvalue_2()
{
auto A = get_set(5000);
auto T = tq::tqdm(A);
T.set_prefix("tqdm from lvalue ");
for (auto&& t : T)
{
t *= 2;
usleep(sleep_time);
T << t;
}
}
void test_constlvalue()
{
const std::vector<int> A = get_vector(5000);
auto T = tq::tqdm(A);
T.set_prefix("tqdm from const lvalue ");
for (auto&& t : T)
{
usleep(sleep_time);
T << t;
}
}
void test_trange()
{
auto T = tq::trange(100, 5000);
T.set_prefix("tqdm range ");
for (auto t : T)
{
usleep(sleep_time);
T << t;
}
}
void test_timer()
{
tq::tqdm_timer timer(2.0);
timer.set_prefix("tqdm timer ");
for (auto a : timer) { usleep(50000); }
}
int main()
{
test_timer();
std::cout << '\n';
test_lvalue();
std::cout << '\n';
test_lvalue_2();
std::cout << '\n';
test_constlvalue();
std::cout << '\n';
test_rvalue();
std::cout << '\n';
test_trange();
std::cout << '\n';
return 0;
}