#elapsed-time #measure #elapsed #wall #human-readable #time #humantime

measure_time

Provices macros to measure the time until end of scope

18 releases

new 0.9.0 Dec 9, 2024
0.8.3 Apr 24, 2024
0.8.2 Apr 2, 2022
0.8.0 Nov 4, 2021
0.1.3 Jun 2, 2017

#25 in Profiling

Download history 92164/week @ 2024-08-22 80465/week @ 2024-08-29 88281/week @ 2024-09-05 81610/week @ 2024-09-12 84097/week @ 2024-09-19 87598/week @ 2024-09-26 89454/week @ 2024-10-03 79676/week @ 2024-10-10 67446/week @ 2024-10-17 66493/week @ 2024-10-24 62999/week @ 2024-10-31 69321/week @ 2024-11-07 74114/week @ 2024-11-14 62258/week @ 2024-11-21 62374/week @ 2024-11-28 55678/week @ 2024-12-05

267,300 downloads per month
Used in 131 crates (12 directly)

MIT license

15KB
291 lines

Docs Crates.io

measure_time

The crate provides macros, which measure the time until end of scope and print the elapsed time in a human readable format.

This is done by creating an object, which measures the time. The time is printed when the object is dropped.

The logging behaviour is the same as other log macros like info!(..)

Installation

Simply add a corresponding entry to your Cargo.toml dependency list:

[dependencies]
measure_time = "0.8"

Examples

use measure_time::{info_time, debug_time, trace_time, error_time, print_time};
fn main() {
    info_time!("measure function");
    {
        debug_time!("{:?}", "measuring block");
        let mut sum = 0;
        for el in 0..50000 {
            sum+=el;
        }
        println!("{:?}", sum);
    }
    trace_time!("{:?}", "trace");
    print_time!("print");
    error_time!(target: "measure_time", "custom target");
}

Changelog

Version 0.4

Objects to measure time are only created when the log level is enabled, else None will be created

Version 0.4.2

Add error and warn levels

Version 0.5.0

Change time formatting for improved readability

Version 0.6.0

Behaviour is now the same as other log macros (eg. info!). Reexporting log crate macros via pub use. Previously all tracing was made to the measure_time target (e.g. RUST_LOG=measure_time=debug). This is now fixed. Added a small example (https://github.com/PSeitz/rust_measure_time/tree/master/measure_time_example).

Version 0.7.0

Support 2018 imports, with improved macro import hygiene.

Version 0.8.0

Fix human readable time, see https://github.com/PSeitz/rust_measure_time/commit/bd829342aaed87db84f49ee6f7f46749b8c8e2ca for details.

Version 0.8.1

Use wasm-compatible Instant https://github.com/PSeitz/rust_measure_time/issues/3

Version 0.9

Use std::Instant

Dependencies

~86KB