-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create a simple profiler for Rust code
- Loading branch information
Showing
10 changed files
with
158 additions
and
15 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
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
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,43 @@ | ||
#[cfg(feature = "profiling")] | ||
pub struct Profiler { | ||
label: String, | ||
start: std::time::Instant, | ||
} | ||
|
||
#[cfg(feature = "profiling")] | ||
impl Profiler { | ||
pub fn start(label: &str) -> Self { | ||
Profiler { | ||
label: label.to_owned(), | ||
start: std::time::Instant::now(), | ||
} | ||
} | ||
|
||
pub fn end(self) { | ||
let duration = self.start.elapsed(); | ||
println!("{} - Elapsed time: {:?}", self.label, duration); | ||
} | ||
} | ||
|
||
#[cfg(feature = "profiling")] | ||
impl Drop for Profiler { | ||
fn drop(&mut self) { | ||
let duration = self.start.elapsed(); | ||
println!("{} - Elapsed time: {:?}", self.label, duration); | ||
} | ||
} | ||
|
||
// Provide no-op implementations when profiling feature is not enabled | ||
#[cfg(not(feature = "profiling"))] | ||
pub struct Profiler; | ||
|
||
#[cfg(not(feature = "profiling"))] | ||
impl Profiler { | ||
pub fn start(_label: &str) -> Self { | ||
Profiler {} | ||
} | ||
|
||
pub fn end(self) { | ||
// Do nothing | ||
} | ||
} |
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