-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Emit statistics from puzzle solver. (#17)
The Puzzle type can optionally be configured to use a profiler by passing the `Profile` or `NoProfile` type parameter. If `NoProfile` is chosen, no runtime cost is incurred. Currently, the following statistics are tracked: * Maximum depth of tree. * Number of nodes in the tree. The unit tests for the puzzles also assert on these statistics to give an additional way of tracking changes in performance. Closes #14.
- Loading branch information
1 parent
a14f00b
commit 563aae0
Showing
7 changed files
with
133 additions
and
25 deletions.
There are no files selected for viewing
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,60 @@ | ||
pub trait Profiler { | ||
fn new() -> Self; | ||
fn move_up(&mut self); | ||
fn move_down(&mut self); | ||
fn add_nodes(&mut self, node_count: u8); | ||
} | ||
|
||
pub struct NoProfile; | ||
|
||
impl Profiler for NoProfile { | ||
fn new() -> NoProfile { | ||
NoProfile | ||
} | ||
|
||
fn move_up(&mut self) {} | ||
|
||
fn move_down(&mut self) {} | ||
|
||
fn add_nodes(&mut self, _node_count: u8) {} | ||
} | ||
|
||
pub struct Profile { | ||
current_depth: u8, | ||
pub max_depth: u8, | ||
pub node_count: u32, | ||
} | ||
|
||
impl Profile { | ||
pub fn print(&self) -> String { | ||
format!( | ||
"Max Depth: {}\nNode Count: {}\n", | ||
self.max_depth, self.node_count | ||
) | ||
} | ||
} | ||
|
||
impl Profiler for Profile { | ||
fn new() -> Profile { | ||
Profile { | ||
current_depth: 1, | ||
max_depth: 1, | ||
node_count: 1, | ||
} | ||
} | ||
|
||
fn move_up(&mut self) { | ||
self.current_depth -= 1; | ||
} | ||
|
||
fn move_down(&mut self) { | ||
self.current_depth += 1; | ||
if self.current_depth > self.max_depth { | ||
self.max_depth = self.current_depth; | ||
} | ||
} | ||
|
||
fn add_nodes(&mut self, node_count: u8) { | ||
self.node_count += node_count as u32; | ||
} | ||
} |