Created
August 29, 2017 20:08
-
-
Save ben-albrecht/33978abe6449e7b8089322a003cbd98c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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