pub struct ExecutionTime { /* private fields */ }
Expand description
Measures the execution time of a code block.
This struct provides methods to start a timer and print the elapsed time in a user-friendly format.
Implementations§
Source§impl ExecutionTime
impl ExecutionTime
Sourcepub fn start() -> Self
pub fn start() -> Self
Starts a new stopwatch.
This function initializes the timer by recording the current time.
§Examples
use execution_time::ExecutionTime;
let timer = ExecutionTime::start();
// ... your code here ...
timer.print_elapsed_time();
Sourcepub fn get_duration(&self) -> Duration
pub fn get_duration(&self) -> Duration
Gets the elapsed time as a Duration
.
Duration
represents a span of time composed of whole seconds
and a fractional part represented in nanoseconds.
Sourcepub fn get_time(&self) -> Time
pub fn get_time(&self) -> Time
Gets the elapsed time as a Time
struct.
This method converts the Duration
into a Time
struct, which
represents the time in terms of days, hours, minutes, and seconds.
Sourcepub fn get_elapsed_time(&self) -> String
pub fn get_elapsed_time(&self) -> String
Calculates the time elapsed since the timer was started and formats it as a string.
This method calculates the elapsed time, formats it into a readable string,
and includes both the formatted time and the raw Duration
for debugging.
Sourcepub fn print_elapsed_time(&self)
pub fn print_elapsed_time(&self)
Prints the time elapsed since the timer was started to the console.
This method prints the formatted elapsed time to stdout
.