feat: add DHAT profiler (#52)
This commit is contained in:
@@ -20,6 +20,7 @@ mod args {
|
||||
day: Day,
|
||||
release: bool,
|
||||
time: bool,
|
||||
dhat: bool,
|
||||
submit: Option<u8>,
|
||||
},
|
||||
All {
|
||||
@@ -51,6 +52,7 @@ mod args {
|
||||
release: args.contains("--release"),
|
||||
submit: args.opt_value_from_str("--submit")?,
|
||||
time: args.contains("--time"),
|
||||
dhat: args.contains("--dhat"),
|
||||
},
|
||||
Some(x) => {
|
||||
eprintln!("Unknown command: {x}");
|
||||
@@ -91,8 +93,9 @@ fn main() {
|
||||
day,
|
||||
release,
|
||||
time,
|
||||
dhat,
|
||||
submit,
|
||||
} => solve::handle(day, release, time, submit),
|
||||
} => solve::handle(day, release, time, dhat, submit),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -2,10 +2,17 @@ use std::process::{Command, Stdio};
|
||||
|
||||
use crate::template::Day;
|
||||
|
||||
pub fn handle(day: Day, release: bool, time: bool, submit_part: Option<u8>) {
|
||||
pub fn handle(day: Day, release: bool, time: bool, dhat: bool, submit_part: Option<u8>) {
|
||||
let mut cmd_args = vec!["run".to_string(), "--bin".to_string(), day.to_string()];
|
||||
|
||||
if release {
|
||||
if dhat {
|
||||
cmd_args.extend([
|
||||
"--profile".to_string(),
|
||||
"dhat".to_string(),
|
||||
"--features".to_string(),
|
||||
"dhat-heap".to_string(),
|
||||
]);
|
||||
} else if release {
|
||||
cmd_args.push("--release".to_string());
|
||||
}
|
||||
|
||||
|
||||
@@ -52,6 +52,10 @@ macro_rules! solution {
|
||||
/// The current day.
|
||||
const DAY: $crate::template::Day = $crate::day!($day);
|
||||
|
||||
#[cfg(feature = "dhat-heap")]
|
||||
#[global_allocator]
|
||||
static ALLOC: dhat::Alloc = dhat::Alloc;
|
||||
|
||||
fn main() {
|
||||
use $crate::template::runner::*;
|
||||
let input = $crate::template::read_file("inputs", DAY);
|
||||
|
||||
@@ -31,7 +31,14 @@ fn run_timed<I: Clone, T>(
|
||||
hook: impl Fn(&T),
|
||||
) -> (T, Duration, u128) {
|
||||
let timer = Instant::now();
|
||||
let result = func(input.clone());
|
||||
let result = {
|
||||
let input = input.clone();
|
||||
|
||||
#[cfg(feature = "dhat-heap")]
|
||||
let _profiler = dhat::Profiler::new_heap();
|
||||
|
||||
func(input)
|
||||
};
|
||||
let base_time = timer.elapsed();
|
||||
|
||||
hook(&result);
|
||||
|
||||
Reference in New Issue
Block a user