execution-time 0.1.6

simple way to measure and display the execution time
Documentation

Execution Time

This Rust project provides a simple way to measure and display the execution time of code blocks. It allows you to start a timer and then print the elapsed time in a human-readable format, including days, hours, minutes, and seconds.

Usage

  1. Add the dependency to your Cargo.toml file:

    [dependencies]
    execution-time = "0.1"
    
  2. Import and Use the library in your main.rs file.

    use execution_time::ExecutionTime;
    
    fn main() {
        let timer = ExecutionTime::start();
    
        // Simulate some work being done
        std::thread::sleep(std::time::Duration::from_millis(1234));
    
        // Print the elapsed time
        timer.print_elapsed_time();
        // or 
        // println!("Elapsed time: {}", timer.get_elapsed_time());
    }
    
  3. Examples

    To run the examples and see the output for different elapsed times:

    1. Clone the repository and run the tests:
    git clone https://github.com/claudiofsr/execution-time.git
    cd execution-time
    cargo test -- --show-output
    
    1. The output:
    ---- tests::elapsed_time_less_than_minute stdout ----
    total_seconds: 0.01516345
    formatted_output: 0.0152 second
    
    ---- tests::elapsed_time_more_than_minute stdout ----
    total_seconds: 65.080012345
    formatted_output: 1 minute, 5.0800 seconds (65.0800 seconds)
    
    ---- tests::elapsed_time_more_than_hour stdout ----
    total_seconds: 3700.05689123
    formatted_output: 1 hour, 1 minute, 40.0569 seconds (3700.0569 seconds)
    
    ---- tests::elapsed_time_more_than_day stdout ----
    total_seconds: 86400.0 + 2.0 * 3600.0 + 5.0 * 60.0 + 28.03
    formatted_output: 1 day, 2 hours, 5 minutes, 28.0300 seconds (93928.0300 seconds)