Chroniker
A simple library to help with time in rust
Usage
Chroniker has two main functions. The sleep function and the Timer API. However it also has some other utilities. One of them is the function to get the unix time.
The Sleep Function
The first, the sleep function is simply there too make sleeping simple. For instance, the next example sleeps the program for 1 second (or 1000 milliseconds).
;
sleep
The Timer API
The timer API makes timer programs very simple to time different parts of the program. To start the timer you call the timer new function. For instance:
let timer = new;
After that the timer automatically starts. To get the time you have two options. You can either print it or call the elapsed_millis() method to get the amount of milliseconds passed. Continuing on the previous example we get:
println!;
let time_passed: i64 = timer.elapsed_millis;
If you want to reset the timer you will need to call the reset method like this:
//Create the timer
let mut timer = new;
//Do first operation
foo;
//Print results and then reset the timer
println!;
timer.reset;
//Do second operation
bar;
//Reprint the results
println!;
To see a complete version see the "getting_started" example. Run:
Examples
Most of the other utilities are covered in examples.
Getting Started
Covers the Timer API
$ cargo run --example getting_started
Millis Time
Covers how to get the UNIX time
$ cargo run --example millis_time
TODO
- Add more to string functions to the timer implementation
- Add a get_unix_time functions
- Add functions to help convert different time units (nanoseconds, milliseconds, seconds, minutes, etc)