-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.cpp
158 lines (139 loc) · 3.57 KB
/
test.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#include "cppm.hpp"
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;
}
int main()
{
int N = 20000;
std::cout << "Progress monitor without total:" << std::endl;
cppm::pm bar1;
// if you want to output the progress monitor to some log file:
// bar1.setOutFilename("/tmp/yadm.log");
for (int i = 0; i < N; i++)
{
usleep(.1);
bar1.update();
// include extra info
bar1 << "loss=" << i;
}
bar1.finish();
std::cout << "Overhead of loop only:" << std::endl;
cppm::pm bar2;
for (int i = 0; i < N; i++)
{
bar2.update();
// include extra info
bar2 << "loss=" << i;
}
bar2.finish();
std::cout << "Progress monitor with given total:" << std::endl;
cppm::pm bar3(N);
for (int i = 0; i < N; i++)
{
usleep(.1);
bar3.update();
// include extra info
bar3 << "loss=" << i;
}
bar3.finish();
std::cout << "CPPM as a timer with an estimated time-to-finish:" << std::endl;
cppm::pm_timer bar4(N * 500 * 1e-6); // estimated time to finish
for (int i = 0; i < N; i++)
{
usleep(500);
bar4.update();
}
bar4.finish();
std::cout << "CPPM with wrapping some iterator (lvalue):" << std::endl;
auto list = get_vector(50000000);
auto bar5 = cppm::iter(list);
for (auto &&t : bar5)
{
// bar5.update(); // SHOULD NOT USE UPDATE
bar5 << t;
}
bar5.finish();
std::cout << "CPPM with wrapping some iterator (rvalue):" << std::endl;
auto bar6 = cppm::iter(get_vector(5000000));
for (auto &&t : bar6)
{
bar6 << t;
}
bar6.finish();
std::cout << "CPPM with easy range (only end):" << std::endl;
for (auto &&t : cppm::range(100))
{
}
std::cout << "CPPM with easy range (start & end):" << std::endl;
for (auto &&t : cppm::range(10, 100))
{
}
std::cout << "CPPM with easy range (start & end & step):" << std::endl;
for (auto &&t : cppm::range(10, 100, 5))
{
}
std::cout << "CPPM with easy range (negative step):" << std::endl;
auto bar7 = cppm::range(1.4e2, -100.2, -5.5);
for (auto &&t : bar7)
{
// bar7.update(); // SHOULD NOT USE UPDATE
bar7 << "val=" << t;
}
bar7.finish();
std::cout << "===== All themes =====" << std::endl;
std::cout << "Basic:" << std::endl;
cppm::pm bar;
bar.reset();
bar.set_theme_basic();
bar.set_total(N);
for (int i = 0; i < N; i++)
{
// bar.progress(i, N);
bar.update();
usleep(100);
bar << "loss=" << i;
}
bar.finish();
std::cout << "Braille:" << std::endl;
bar.reset();
bar.set_theme_braille();
for (int i = 0; i < N; i++)
{
bar.progress(i, N);
usleep(300);
}
bar.finish();
std::cout << "Line:" << std::endl;
bar.reset();
bar.set_theme_line();
for (int i = 0; i < N; i++)
{
bar.progress(i, N);
usleep(300);
}
bar.finish();
std::cout << "Circles:" << std::endl;
bar.reset();
bar.set_theme_circle();
for (int i = 0; i < N; i++)
{
bar.progress(i, N);
usleep(300);
}
bar.finish();
bar.reset();
std::cout << "Vertical bars:" << std::endl;
bar.reset();
bar.set_theme_vertical();
for (int i = 0; i < N; i++)
{
bar.progress(i, N);
usleep(300);
}
bar.finish();
return 0;
}