#long #how #macro #cases #measure

time-test

使用一个简单的宏来测量测试用例耗时

5个版本

0.2.3 2022年2月23日
0.2.2 2019年10月12日
0.2.1 2017年9月3日
0.2.0 2017年9月2日
0.1.0 2017年9月2日

#333测试 类别中

Download history 787/week @ 2024-03-14 536/week @ 2024-03-21 786/week @ 2024-03-28 463/week @ 2024-04-04 440/week @ 2024-04-11 248/week @ 2024-04-18 298/week @ 2024-04-25 471/week @ 2024-05-02 516/week @ 2024-05-09 712/week @ 2024-05-16 507/week @ 2024-05-23 234/week @ 2024-05-30 369/week @ 2024-06-06 456/week @ 2024-06-13 553/week @ 2024-06-20 219/week @ 2024-06-27

1,628 每月下载量
22 个crate中(21 个直接) 使用

MIT 许可证

5KB

time_test

time_test 是一个超级简单的crate,你可以用它轻松获取测试运行所需的时间。使用它很简单(见 example/ 中的示例用例)

#[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);
    }
}

将宏 time_test!() 添加到测试中想要测量运行时间的行,测试结果行将显示测试所需的时间

$ # 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 是一个超级简单的crate,你可以用它轻松获取测试运行所需的时间。使用它很简单(见 example/ 中的示例用例)

#[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);
    }
}

将宏 time_test!() 添加到测试中想要测量运行时间的行,测试结果行将显示测试所需的时间

$ # 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

依赖项

~0.6–1MB
~15K SLoC