Built with 🦀🕸 by The Rust and WebAssembly Working Group
The console.time
and console.timeEnd
functions allow you to log the
timing of named operations to the browser's developer tools console. You
call console.time("foo")
when the operation begins, and call
console.timeEnd("foo")
when it finishes.
Additionally, these measurements will show up in your browser's profiler's "timeline" or "waterfall" view.
This API wraps both the time
and timeEnd
calls into a single type
named ConsoleTimer
, ensuring both are called.
Scoped Measurement
Wrap code to be measured in a closure with ConsoleTimer::scope
.
use ConsoleTimer;
let value = scope;
RAII-Style Measurement
For scenarios where ConsoleTimer::scope
can't be used, like with
asynchronous operations, you can use ConsoleTimer::new
to create a timer.
The measurement ends when the timer object goes out of scope / is dropped.
use ConsoleTimer;
use Timeout;
// Start timing a new operation.
let timer = new;
// And then asynchronously finish timing.
let timeout = new;