Skip to content

Commit

Permalink
add README, more doc
Browse files Browse the repository at this point in the history
  • Loading branch information
xu-cheng committed Dec 5, 2019
1 parent 7d2743f commit c808ffc
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ authors = ["Cheng XU <[email protected]>"]
edition = "2018"
build = "build.rs"
license = "MIT OR Apache-2.0"
description = "Measure how long it takes for a program to execute in different clocks"
repository = "https://github.com/xu-cheng/howlong"
documentation = "https://docs.rs/howlong"
readme = "README.md"

[dependencies]
Expand Down
50 changes: 50 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,51 @@
# howlong

This crate allows you to measure how long it takes for a program to execute in different clocks. It ports the functions of the [`boost-chrono`](https://boost.org/libs/chrono) and [`boost-timer`](https://boost.org/libs/timer) libraries.

The following clocks and their corresponding timers are implemented.

* `SystemClock`, `SystemTimer`
* `SteadyClock`, `SteadyTimer` if supported by the system.
* `HighResolutionClock`, `HighResolutionTimer`
* `ProcessRealCPUClock`, `ProcessRealCPUTimer`
* `ProcessUserCPUClock`, `ProcessUserCPUTimer`
* `ProcessSystemCPUClock`, `ProcessSystemCPUTimer`
* `ProcessCPUClock`, `ProcessCPUTimer`
* `ThreadClock`, `ThreadTimer`

## Documentation

<https://doc.rs/howlong>

## Usage

Add this to your `Cargo.toml`:

```toml
[dependencies]
howlong = "0.1"
```

## Examples

```rust
use howlong::*;

let timer = HighResolutionTimer::new();
// do some computations
println!("{:?} have passed.", timer.elapsed());

let timer = ProcessCPUTimer::new();
// do other computations
println!("{}", timer.elapsed());
```

## License

<sup>
Licensed under either of <a href="LICENSE-APACHE">Apache License, Version 2.0</a> or <a href="LICENSE-MIT">MIT license</a> at your option.
</sup>
<br>
<sub>
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
</sub>
2 changes: 1 addition & 1 deletion src/clock/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
//! # Implementations
//!
//! The Implementations of the clocks are based on
//! [`boost-chrono` library](http://boost.org/libs/chrono)
//! [`boost-chrono` library](https://boost.org/libs/chrono).
//! The following table listes the underlying APIs for different clocks.
//!
//! | Clock | Posix | Darwin | Windows |
Expand Down
39 changes: 39 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,42 @@
//! This crate allows you to measure how long it takes for a program to execute in different
//! clocks. It ports the functions of the [`boost-chrono`](https://boost.org/libs/chrono)
//! and [`boost-timer`](https://boost.org/libs/timer) libraries.
//!
//! The following clocks and their corresponding timers are implemented.
//!
//! * [`SystemClock`], [`SystemTimer`]
//! * [`SteadyClock`], [`SteadyTimer`] if supported by the system.
//! * [`HighResolutionClock`], [`HighResolutionTimer`]
//! * [`ProcessRealCPUClock`], [`ProcessRealCPUTimer`]
//! * [`ProcessUserCPUClock`], [`ProcessUserCPUTimer`]
//! * [`ProcessSystemCPUClock`], [`ProcessSystemCPUTimer`]
//! * [`ProcessCPUClock`], [`ProcessCPUTimer`]
//! * [`ThreadClock`], [`ThreadTimer`]
//!
//! See [`crate::clock`] to read more about their differences.
//!
//! # Usage
//!
//! Add this to your `Cargo.toml`:
//! ```toml
//! [dependencies]
//! howlong = "0.1"
//! ```
//!
//! # Examples
//!
//! ```
//! use howlong::*;
//!
//! let timer = HighResolutionTimer::new();
//! // do some computations
//! println!("{:?} have passed.", timer.elapsed());
//!
//! let timer = ProcessCPUTimer::new();
//! // do other computations
//! println!("{}", timer.elapsed());
//! ```
mod types;
pub use types::*;

Expand Down
2 changes: 1 addition & 1 deletion src/timer.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Measure how long a program takes to execute.
//!
//! A varity of timers are implemented using different clocks.
//! See [`crate::clock`] to read more about their difference.
//! See [`crate::clock`] to read more about their differences.
//!
//! # Examples
//!
Expand Down
3 changes: 3 additions & 0 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,11 @@ impl Into<ProcessDuration> for ProcessTimePoint {
/// Like [`Duration`] but captures real, user-CPU, and system-CPU process times.
#[derive(Clone, Copy, Debug, Default)]
pub struct ProcessDuration {
/// [`Duration`] measured by wall-time clock.
pub real: Duration,
/// [`Duration`] measured by user-CPU clock.
pub user: Duration,
/// [`Duration`] measured by system-CPU clock.
pub system: Duration,
}

Expand Down

0 comments on commit c808ffc

Please sign in to comment.