How do you print execution time for each test?

I was just reading a thoughtful article on testing in rust by Matklad.

In that article he recommends defaulting to printing test execution times:

To deal with outliers, print each test’s execution time by default. Having the numbers fly by gives you immediate feedback and incentive to improve.

If you do this, what do you use to do it? Digging around I did find this crate:

I use the built-in test runner in Intellij. It tracks the execution time of all tests on its own.

1 Like

Nice -- never expected to have IDE envy when vscode is working so well

Looks like if you run cargo test using nightly you can print times at least if you allow unstable options

$ cargo test -- --report-time
    Finished test [unoptimized + debuginfo] target(s) in 0.69s
     Running unittests src/ (target/debug/deps/cache-0f6452d8f8bdc1b1)
error: The "report-time" flag is only accepted on the nightly compiler with -Z unstable-options

But actually, you don't need nightly. Just use unstable options, as in

$ cargo test -- -Z unstable-options --report-time

cargo nextest also reports times, without any source changes.


Really interesting -- claims to run your tests more quickly too...

Someone should put time into stabilizing --report-time :wink: :wink: :wink:


This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.