Thanks to visit codestin.com
Credit goes to lib.rs

8 stable releases

2.1.0 Sep 1, 2025
2.0.5 Aug 8, 2025
2.0.2 Apr 22, 2025
2.0.1 Feb 16, 2025
1.2.0 Jan 3, 2025

#185 in Profiling

Codestin Search App Codestin Search App

514 downloads per month

MIT license

6KB
55 lines

MacroTime

time!

MacroTime is very easy to use. To time the execution of a block of code:

use macrotime::*;
let time = time!({
    // do some stuff...
});
println!("This operation took {} ms!", time.as_millis());

dbg_time!

You can also have MacroTime print the time taken to perform a task on its own. To do this:

use macrotime::*;
dbg_time!("context...", {
    // do some stuff...
});

In this scenario, the time will printed in the most relevant unit, so no need for formatting.

Return statements within the debug macro will be propogated to the outer scope, and can be used elsewhere in the code, for minimal disruption to program flow.

let result = dbg_time!("returning 123...", {123});

MacroTime

This crate implements macros that can be used to time arbitrary snippets of code. This allows you to easily test functions on the go, without any fancy boilerplate for benchmarking.

Example

To time a snippet of code, simply:

use macrotime::*;
dbg_time!("task", {
    // write any code here...
});

And the execution time will be logged in the most relevant unit with the 'task' context added for readability. It's that simple.

Documentation

If you'd like to see more examples or learn more about MacroTime, take a look at the documentation. All information listed there should be up to date and tested for the most recent version of the package.

No runtime deps