Skip to content

iopsystems/clocksource

Repository files navigation

clocksource

A Rust library for time and duration types with fixed-size representations, providing coarse (second-resolution) and precise (nanosecond-resolution) variants, plus atomic versions for concurrent use. All types use a single 32-bit or 64-bit integer internally, making them compact and efficient for arithmetic operations.

Getting Started

cargo add clocksource

Usage

use clocksource::coarse;
use clocksource::precise;

// Coarse (second-resolution) monotonic instant
let coarse_start = coarse::Instant::now();
// ... do work ...
let coarse_elapsed: coarse::Duration = coarse_start.elapsed();
println!("elapsed: {} seconds", coarse_elapsed.as_secs());

// Precise (nanosecond-resolution) monotonic instant
let precise_start = precise::Instant::now();
// ... do work ...
let precise_elapsed: precise::Duration = precise_start.elapsed();
println!("elapsed: {} ns", precise_elapsed.as_nanos());

// Unix timestamps
let now = precise::UnixInstant::now();
let coarse_now = coarse::UnixInstant::now();

Links

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.

About

No description, website, or topics provided.

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages