Crates.io | gloo-console-timer |
lib.rs | gloo-console-timer |
version | 0.1.0 |
source | src |
created_at | 2019-09-13 11:51:23.186754 |
updated_at | 2019-09-13 11:51:23.186754 |
description | Convenience crate for working with JavaScript timers |
homepage | https://github.com/rustwasm/gloo |
repository | https://github.com/rustwasm/gloo/tree/master/crates/console-timer |
max_upload_size | |
id | 164550 |
size | 7,531 |
gloo-console-timer
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.
Wrap code to be measured in a closure with ConsoleTimer::scope
.
use gloo_console_timer::ConsoleTimer;
let value = ConsoleTimer::scope("foo", || {
// Place code to be measured here
// Optionally return a value.
});
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 gloo_console_timer::ConsoleTimer;
use gloo_timers::callback::Timeout;
// Start timing a new operation.
let timer = ConsoleTimer::new("foo");
// And then asynchronously finish timing.
let timeout = Timeout::new(1_000, move || {
drop(timer);
});