devalang_wasm/shared/debugger/
mod.rs1use std::time::Instant;
3
4pub struct DebugTimer {
5 start: Instant,
6 label: String,
7}
8
9impl DebugTimer {
10 pub fn new(label: impl Into<String>) -> Self {
11 Self {
12 start: Instant::now(),
13 label: label.into(),
14 }
15 }
16
17 pub fn elapsed_ms(&self) -> f64 {
18 self.start.elapsed().as_secs_f64() * 1000.0
19 }
20
21 pub fn log_elapsed(&self) {
22 }
24}
25
26impl Drop for DebugTimer {
27 fn drop(&mut self) {
28 self.log_elapsed();
29 }
30}
31
32#[cfg(test)]
33mod tests {
34 use super::*;
35 use std::thread;
36 use std::time::Duration;
37
38 #[test]
39 fn test_debug_timer() {
40 let timer = DebugTimer::new("test");
41 thread::sleep(Duration::from_millis(10));
42 assert!(timer.elapsed_ms() >= 10.0);
43 }
44}