Skip to content

Commit

Permalink
avoid calling Instant::now() when timing disabled (#181)
Browse files Browse the repository at this point in the history
This fixes the library in WebAssembly, which panics when Instant::now()
is called.
  • Loading branch information
io12 authored Jan 19, 2025
1 parent 26e5fe9 commit 174c9ca
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions metamath-rs/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,13 +413,15 @@ impl Default for Database {
}

pub(crate) fn time<R, F: FnOnce() -> R>(opts: &DbOptions, name: &str, f: F) -> R {
let now = Instant::now();
let ret = f();
if opts.timing {
let now = Instant::now();
let ret = f();
// no as_msecs :(
println!("{} {}ms", name, (now.elapsed() * 1000).as_secs());
ret
} else {
f()
}
ret
}

impl Drop for Database {
Expand Down

0 comments on commit 174c9ca

Please sign in to comment.