Skip to content

Instantly share code, notes, and snippets.

@ben-albrecht
Created August 29, 2017 20:08
Show Gist options
  • Save ben-albrecht/33978abe6449e7b8089322a003cbd98c to your computer and use it in GitHub Desktop.
Save ben-albrecht/33978abe6449e7b8089322a003cbd98c to your computer and use it in GitHub Desktop.
use Time;
use IO;
config const toolbarWidth = 40;
proc main() {
const D = {1..1000000};
var arr: [D] real;
writeln('Populating array');
for i in loadingBar(D, D.size) {
arr[i] = i**i;
}
writeln('Array populated');
}
/* Print a loading bar for the iterable object */
iter loadingBar(iterable, size) {
stdout.writef("[%s]", " " * toolbarWidth);
stdout.flush();
stdout.write("\b" * (toolbarWidth+1)); // return to start of line, after '['
const increment = (size / toolbarWidth): int;
for i in iterable {
if i % increment == 0 {
stdout.write("-");
stdout.flush();
}
yield i;
}
stdout.write("\n");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment