Skip to content

Commit

Permalink
Compute speed as more general exponential average
Browse files Browse the repository at this point in the history
  • Loading branch information
oir committed Nov 28, 2023
1 parent 5b9f3f8 commit 2c96520
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 104 deletions.
22 changes: 11 additions & 11 deletions demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ int main(int /*argc*/, char** /*argv*/) {
anim.done();
}

for (auto speed : {Speed::None, Speed::Overall, Speed::Last}) {
std::vector<std::optional<double>> speeds{std::nullopt, 0, 0.1, 1};
for (auto speed : speeds) {
std::atomic<size_t> work{0};
auto c =
Counter(&work).message("Doing stuff").speed_unit("tk/s").speed(speed);
Expand All @@ -27,7 +28,7 @@ int main(int /*argc*/, char** /*argv*/) {
c.done();
}

for (auto speed : {Speed::None, Speed::Overall, Speed::Last}) {
for (auto speed : speeds) {
float work{0};
auto c =
Counter(&work).message("Doing stuff").speed_unit("tk/s").speed(speed);
Expand All @@ -39,7 +40,7 @@ int main(int /*argc*/, char** /*argv*/) {
c.done();
}

for (auto speed : {Speed::None, Speed::Overall, Speed::Last}) {
for (auto speed : speeds) {
unsigned long long work{677};
auto c = Counter(&work).message("Decreasing").speed_unit("").speed(speed);
c.show();
Expand All @@ -50,7 +51,7 @@ int main(int /*argc*/, char** /*argv*/) {
// Let destructor do the c.done() this time
}

for (auto speed : {Speed::None, Speed::Overall, Speed::Last}) {
for (auto speed : speeds) {
for (auto sty : {Blocks, Bars, Arrow}) {
std::atomic<size_t> work{0};
auto bar = ProgressBar(&work)
Expand All @@ -73,8 +74,8 @@ int main(int /*argc*/, char** /*argv*/) {
// in terms of tokens per second.'
std::atomic<size_t> sents{0}, toks{0};
auto bar =
ProgressBar(&sents).total(1010).message("Sents") |
Counter(&toks).message("Toks").speed_unit("tok/s").speed(Speed::Last);
ProgressBar(&sents).total(1010).message("Sents").speed(1) |
Counter(&toks).message("Toks").speed(1);
bar.show();
for (int i = 0; i < 1010; i++) {
std::this_thread::sleep_for(13ms);
Expand All @@ -85,9 +86,8 @@ int main(int /*argc*/, char** /*argv*/) {
}

{ // Decreasing progress
// WARN: negative speeds will underflow if you use an unsigned progress type
long work{1010};
auto bar = ProgressBar(&work).total(1010).speed(Speed::Last);
unsigned long work{1010};
auto bar = ProgressBar(&work).total(1010).speed(1);
bar.show();
for (int i = 0; i < 1010; i++) {
std::this_thread::sleep_for(13ms);
Expand All @@ -105,7 +105,7 @@ int main(int /*argc*/, char** /*argv*/) {
auto bar = ProgressBar(&sents)
.total(20100)
.message("Sents")
.speed(Speed::Last)
.speed(1)
.no_tty();
bar.show();
for (int i = 0; i < 20100; i++) {
Expand All @@ -120,7 +120,7 @@ int main(int /*argc*/, char** /*argv*/) {
std::atomic<size_t> sents{0}, toks{0};
auto bar =
ProgressBar(&sents).total(20100).message("Sents") |
Counter(&toks).message("Toks").speed_unit("tok/s").speed(Speed::Last);
Counter(&toks).message("Toks").speed_unit("tok/s").speed(1);
bar.no_tty();
bar.show();
for (int i = 0; i < 20100; i++) {
Expand Down
Loading

0 comments on commit 2c96520

Please sign in to comment.