fun_time
fun_time is a simple Rust library that allows you to easily time your function calls with a simple attribute!
Basic example
The above will print Starting: Heavy calculations when the function starts, and Heavy calculations: Done in <duration> on completion.
Configuration
There are various attributes that allow you to configure the behavior of the fun_time attribute.
messageallows you to set a message that will be printed when starting, and when done.whenallows you to configure when the timing should be collected. The possible values for this are:"always"which as the name might suggest will always collect timing information, and"debug"which will only collect whencfg!(debug_assertions)evaluates totrue.give_backis a flag that makes it so the wrapped function will now return the elapsed time instead of printing it. For this it modifies the return type from for example:-> &'a strto-> (&'a str, std::time::Duration). This allows you to handle printing or storing the timing information.reporting(can not be used in combination with give_back) determines how the reporting is done. The possible options are:"println"which will print to stdout usingprintln!. The"log"option is only available when thelogfeature is used. This will use the log crate withinfo!level logs.
Reporting
The reported messages are formatted as follows:
Start message: "Starting: YOUR_MESSAGE_HERE"
Done message: "YOUR_MESSAGE_HERE: Done in DURATION"