Skip to content

Instantly share code, notes, and snippets.

@Xophmeister
Created June 29, 2012 13:18
Show Gist options
  • Save Xophmeister/3017860 to your computer and use it in GitHub Desktop.
Save Xophmeister/3017860 to your computer and use it in GitHub Desktop.
Just a silly little timer!
import std.stdio, core.time;
class msTimer {
TickDuration start;
this() { reset(); }
long split() { return (TickDuration.currSystemTick() - start).msecs(); }
void reset() { start = TickDuration.currSystemTick(); }
}
void wait(long ms) {
auto waiter = new msTimer();
while(waiter.split() < ms) {};
}
void main() {
auto stopWatch = new msTimer();
writeln("Current split: ", stopWatch.split(), "ms");
wait(2500);
writeln("Current split: ", stopWatch.split(), "ms");
stopWatch.reset();
writeln("Current split: ", stopWatch.split(), "ms");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment