From 27613db8f7b20686ac401f67e9cbc16bf4f68d59 Mon Sep 17 00:00:00 2001 From: Dylan Thies Date: Sat, 6 Jan 2024 11:46:01 -0500 Subject: [PATCH] adding dhat to day template --- template/day-n/Cargo.toml | 4 ++++ template/day-n/src/main.rs | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/template/day-n/Cargo.toml b/template/day-n/Cargo.toml index cc7613c..f15b6d8 100644 --- a/template/day-n/Cargo.toml +++ b/template/day-n/Cargo.toml @@ -14,6 +14,10 @@ itertools.workspace = true log.workspace = true error-stack.workspace = true thiserror.workspace = true +dhat.workspace = true [dev-dependencies] test-log.workspace = true + +[features] +dhat-heap = [] diff --git a/template/day-n/src/main.rs b/template/day-n/src/main.rs index 64b3152..b2fe57a 100644 --- a/template/day-n/src/main.rs +++ b/template/day-n/src/main.rs @@ -6,6 +6,10 @@ use {{ crate_name }}::part2; use error_stack::{Result, ResultExt}; use thiserror::Error; +#[cfg(feature = "dhat-heap")] +#[global_allocator] +static ALLOC: dhat::Alloc = dhat::Alloc; + #[derive(Debug, Error)] enum {{ project-name | upper_camel_case }}Error { #[error("Part 1 failed")] @@ -15,6 +19,9 @@ enum {{ project-name | upper_camel_case }}Error { } fn main() -> Result<(), {{ project-name | upper_camel_case }}Error> { + #[cfg(feature = "dhat-heap")] + let _profiler = dhat::Profiler::new_heap(); + let input = include_str!("./input.txt"); let part1_result = part1(input).change_context({{ project-name | upper_camel_case }}Error::Part1Error)?; println!("part 1: {part1_result}");