-
Notifications
You must be signed in to change notification settings - Fork 218
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace `Instant::now` with a custom library, that will use appriate time/date functions for the platforms. For native, it is `std::time`, for WASM in should probably be `performance::now()` but it is a no-op stub for now.
- Loading branch information
Showing
10 changed files
with
104 additions
and
41 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[package] | ||
name = "elapsed" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
|
||
[target.'cfg(target_arch = "wasm32")'.dependencies] | ||
js-sys.workspace = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#[cfg(target_arch = "wasm32")] | ||
mod wasm; | ||
#[cfg(target_arch = "wasm32")] | ||
pub use crate::wasm::ElapsedTimeCounter; | ||
|
||
#[cfg(not(target_arch = "wasm32"))] | ||
mod native; | ||
#[cfg(not(target_arch = "wasm32"))] | ||
pub use crate::native::ElapsedTimeCounter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
use std::time::{Duration, Instant}; | ||
|
||
pub struct ElapsedTimeCounter { | ||
instant: Instant, | ||
} | ||
|
||
impl ElapsedTimeCounter { | ||
pub fn start() -> Self { | ||
let instant = Instant::now(); | ||
|
||
Self { instant } | ||
} | ||
|
||
pub fn elapsed_time(&self) -> Duration { | ||
self.instant.elapsed() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
use std::time::Duration; | ||
|
||
/// TODO: this is a stub that always returns 0 as elapsed time | ||
/// In should use performance::now() instead | ||
pub struct ElapsedTimeCounter {} | ||
|
||
impl ElapsedTimeCounter { | ||
pub fn start() -> Self { | ||
Self {} | ||
} | ||
|
||
pub fn elapsed_time(&self) -> Duration { | ||
Duration::from_millis(0u64) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters