3 个版本
使用旧的 Rust 2015
| 0.1.2 | 2017年5月6日 | 
|---|---|
| 0.1.1 | 2017年3月17日 | 
| 0.1.0 | 2017年3月17日 | 
#11 in #nanosecond
每月 24 次下载
15KB
195 代码行
精细粒度
一个带有计圈功能和纳秒级分辨率的 Rust 计时器。
示例
获取单个测量值
extern crate fine_grained;
use fine_grained::Stopwatch;
fn main() {
    // Get a new stopwatch and start it.
    let mut stopwatch = Stopwatch::start_new();
    // Do something long and time it.
    // do_something_long();
    println!("Duration: {duration}ns", duration = stopwatch);
    stopwatch.stop();
}
获取重复任务的测量值和总时间
extern crate fine_grained;
use fine_grained::Stopwatch;
fn main() {
    // Get a new stopwatch and start it.
    let mut stopwatch = Stopwatch::start_new();
    // Do something repetitive you want to time.
    for _ in 0..10 {
        // do_something_repetitive();
        stopwatch.lap();
    }
    stopwatch.stop();
    // Print the timing results.
    for (i, &lap) in stopwatch.laps().into_iter().enumerate() {
        println!("Round {i}: {duration}ns", i = i, duration = lap);
    }
    println!("Total time: {duration}ns", duration = stopwatch);
}
获取多个独立任务的测量值和总时间
extern crate fine_grained;
use fine_grained::Stopwatch;
fn main() {
    // Get a new stopwatch and start it.
    let mut stopwatch = Stopwatch::start_new();
    // Do foo.
    // do_foo();
    let time_to_do_foo: u64 = stopwatch.lap();
    // Do bar.
    // do_bar();
    let time_to_do_bar: u64 = stopwatch.lap();
    // Do foobar.
    // do_foobar();
    let time_to_do_foobar: u64 = stopwatch.lap();
    stopwatch.stop();
    println!("Time to do foo: {duration}ns", duration = time_to_do_foo);
    println!("Time to do bar: {duration}ns", duration = time_to_do_bar);
    println!("Time to do foobar: {duration}ns", duration = time_to_do_foobar);
    println!("Total time: {duration}ns", duration = stopwatch);
}
灵感来源
灵感来自 Chucky Ellison 的计时器 (https://github.com/ellisonch/rust-stopwatch).
许可证
CRGP 许可证受以下之一的许可
- Apache 许可证 2.0 版本 (LICENSE-APACHE或 https://apache.ac.cn/licenses/LICENSE-2.0)
- MIT 许可证 (LICENSE-MIT或 https://open-source.org.cn/licenses/MIT)
根据您的选择。
贡献
除非您明确表示,否则任何有意提交给作品并由您包括在内的贡献,根据 Apache-2.0 许可证的定义,应按上述方式双许可,不附加任何额外条款或条件。
依赖
~0.6–1MB
~15K SLoC