#unit-testing #measure #long #test-cases #how #macro

time-test

Measure how long your test cases take with one simple macro

6 releases

0.3.0 Nov 2, 2024
0.2.3 Feb 23, 2022
0.2.2 Oct 12, 2019
0.2.1 Sep 3, 2017
0.1.0 Sep 2, 2017

#114 in Testing

Download history 540/week @ 2024-08-17 309/week @ 2024-08-24 382/week @ 2024-08-31 368/week @ 2024-09-07 469/week @ 2024-09-14 1046/week @ 2024-09-21 489/week @ 2024-09-28 749/week @ 2024-10-05 441/week @ 2024-10-12 726/week @ 2024-10-19 737/week @ 2024-10-26 816/week @ 2024-11-02 640/week @ 2024-11-09 550/week @ 2024-11-16 696/week @ 2024-11-23 1294/week @ 2024-11-30

3,309 downloads per month
Used in 22 crates (21 directly)

MIT license

5KB

time_test

time_test is a super simple crate that you can use to easily obtain how long your tests took to run. Using it is simple (see example/ for an example use case):

#[macro_use]
extern crate time_test;

#[cfg(test)]
mod tests {
    #[test]
    fn my_test() {
        time_test!();

        println!("hello world");

        {
            time_test!("sub-assert 1");
            assert!(true);
        }
        assert_eq!(1, 1);
    }
}

Adding the time_test!() macro to the line in your test from which you want to measure the test duration will result in the duration that the test has taken being shown in the test result line:

$ # 1 test thread so that the output is not garbled.
$ cargo test -- --test-threads=1

    Finished dev [unoptimized + debuginfo] target(s) in 0.78 secs
     Running target/debug/deps/example-a84426a5de188514

running 1 test
test example::tests::my_test ... (sub-assert 1 took PT0.000002421S) (took PT0.000004178S) ok

lib.rs:

time_test is a super simple crate that you can use to easily obtain how long your tests took to run. Using it is simple (see example/ for an example use case):

#[macro_use] extern crate time_test;

#[cfg(test)]
mod tests {
    #[test]
    fn my_test() {
        time_test!();

        println!("hello world");

        {
            time_test!("sub-assert 1");
            assert!(true);
        }
        assert_eq!(1, 1);
    }
}

Adding the time_test!() macro to the line in your test from which you want to measure the test duration will result in the duration that the test has taken being shown in the test result line:

$ # 1 test thread so that the output is not garbled.
$ cargo test -- --test-threads=1

    Finished dev [unoptimized + debuginfo] target(s) in 0.78 secs
     Running target/debug/deps/example-a84426a5de188514

running 1 test
test example::tests::my_test ... (sub-assert 1 took PT0.000002421S) (took PT0.000004178S) ok

Dependencies

~760KB
~14K SLoC