Skip to content

Commit

Permalink
Merge pull request #7 from sheroz/sheroz-patch1
Browse files Browse the repository at this point in the history
added benchmarks for binary search tree
  • Loading branch information
sheroz committed Sep 5, 2023
2 parents ec34be4 + 8fb95ef commit 3bfec5c
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 7 deletions.
7 changes: 7 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,10 @@ edition = "2021"

[dependencies]
uuid = { version = "1.4.1", features = ["v4"] }

[dev-dependencies]
criterion = "0.5"

[[bench]]
name = "bst_benches"
harness = false
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

Tree and parent-child relationship samples for learning purposes

Samples included:

- [Generic Tree](src/generic_tree.rs)
- [Binary Tree](src/binary_tree.rs)
- [Binary Search Tree](src/binary_search_tree.rs)

## Useful insights

- [Learn Rust With Entirely Too Many Linked Lists](https://rust-unofficial.github.io/too-many-lists/)
- [Tree Data Structure](https://www.programiz.com/dsa/trees)
- [Learn Rust With Entirely Too Many Linked Lists](https://rust-unofficial.github.io/too-many-lists/)
23 changes: 23 additions & 0 deletions benches/bst_benches.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use criterion::{criterion_group, criterion_main, Criterion};
use tree_samples_rs::binary_search_tree::*;
use tree_samples_rs::binary_tree::*;

fn benchmark_is_binary_search_tree_versions(c: &mut Criterion) {
let root = utils::populate_balanced_binary_search_tree();

c.bench_function("is_binary_search_tree_v1", |b| {
b.iter(|| BinarySearchTree::is_binary_search_tree_v1(&root))
});

c.bench_function("is_binary_search_tree_v2", |b| {
b.iter(|| BinarySearchTree::is_binary_search_tree_v2(&root))
});

c.bench_function("is_binary_search_tree_v3", |b| {
b.iter(|| BinarySearchTree::is_binary_search_tree_v3(&root))
});
}

criterion_group!(benches, benchmark_is_binary_search_tree_versions,);

criterion_main!(benches);
2 changes: 1 addition & 1 deletion src/binary_search_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ impl BinarySearchTree {
#[cfg(test)]
mod tests {
use super::*;
use crate::binary_tree::test_utils::*;
use crate::binary_tree::utils::*;

#[test]
fn insert_recursion() {
Expand Down
5 changes: 2 additions & 3 deletions src/binary_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,7 @@ impl BinaryTree {
}
}

#[cfg(test)]
pub mod test_utils {
pub mod utils {

use super::*;
pub const NODES_COUNT: usize = 15;
Expand Down Expand Up @@ -275,7 +274,7 @@ pub mod test_utils {
mod tests {
use std::collections::HashMap;

use crate::binary_tree::{test_utils::*, BinaryTree};
use crate::binary_tree::{utils::*, BinaryTree};

#[test]
fn populate_node_ref_list_test() {
Expand Down

0 comments on commit 3bfec5c

Please sign in to comment.