1 unstable release

0.1.0 Sep 13, 2019

#1564 in WebAssembly

Download history 1629/week @ 2024-02-04 1638/week @ 2024-02-11 1817/week @ 2024-02-18 1920/week @ 2024-02-25 1659/week @ 2024-03-03 1313/week @ 2024-03-10 1516/week @ 2024-03-17 2173/week @ 2024-03-24 1835/week @ 2024-03-31 1496/week @ 2024-04-07 1868/week @ 2024-04-14 1567/week @ 2024-04-21 1512/week @ 2024-04-28 1219/week @ 2024-05-05 1182/week @ 2024-05-12 1374/week @ 2024-05-19

5,436 downloads per month

MIT/Apache

8KB

gloo-console-timer

Build Status Crates.io version Download docs.rs docs

API Docs | Contributing | Chat

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.

See MDN for more info.

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 gloo_console_timer::ConsoleTimer;

let value = ConsoleTimer::scope("foo", || {
    // Place code to be measured here
    // Optionally return a value.
});

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 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);
});

Dependencies

~6.5–9MB
~171K SLoC