-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Add performance benchmarks for various modules and expose funda… #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,30 @@ | ||||||||
| use algs4_advanced::fenwick_tree::FenwickTree; | ||||||||
| use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion}; | ||||||||
| use rand::prelude::SliceRandom; | ||||||||
| use rand::thread_rng; | ||||||||
|
|
||||||||
| fn advanced_benchmark(c: &mut Criterion) { | ||||||||
| let mut group = c.benchmark_group("advanced"); | ||||||||
|
|
||||||||
| for size in [1000, 5000].iter() { | ||||||||
| let mut rng = thread_rng(); | ||||||||
| let mut data: Vec<i32> = (0..*size as i32).collect(); | ||||||||
| data.shuffle(&mut rng); | ||||||||
|
Comment on lines
+10
to
+12
|
||||||||
| let mut rng = thread_rng(); | |
| let mut data: Vec<i32> = (0..*size as i32).collect(); | |
| data.shuffle(&mut rng); |
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
| @@ -0,0 +1,174 @@ | ||||
| use algs4_fundamentals::collections::linked_bag::LinkedBag; | ||||
| use algs4_fundamentals::collections::linked_queue::LinkedQueue; | ||||
| use algs4_fundamentals::collections::linked_stack::LinkedStack; | ||||
| use algs4_fundamentals::collections::resizing_array_bag::ResizingArrayBag; | ||||
| use algs4_fundamentals::collections::resizing_array_queue::ResizingArrayQueue; | ||||
| use algs4_fundamentals::collections::resizing_array_stack::ResizingArrayStack; | ||||
| use algs4_fundamentals::union_find::quick_find_uf::QuickFindUF; | ||||
| use algs4_fundamentals::union_find::quick_union_uf::QuickUnionUF; | ||||
| use algs4_fundamentals::union_find::weighted_quick_union_uf::WeightedQuickUnionUF; | ||||
| use algs4_fundamentals::union_find::weighted_quick_union_uf::WeightedQuickUnionUF as UF; // UF trait might not be public or exist as named | ||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||
| use algs4_fundamentals::union_find::weighted_quick_union_uf::WeightedQuickUnionUF as UF; // UF trait might not be public or exist as named |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot
AI
Nov 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable ops is defined but never used. Remove this unused variable.
| let ops = size * 2; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,26 @@ | ||||||||||
| use algs4_geometry::graham_scan::GrahamScan; | ||||||||||
| use algs4_geometry::point2d::Point2D; | ||||||||||
| use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion}; | ||||||||||
| use rand::{thread_rng, Rng}; | ||||||||||
|
|
||||||||||
| fn geometry_benchmark(c: &mut Criterion) { | ||||||||||
| let mut group = c.benchmark_group("geometry"); | ||||||||||
|
|
||||||||||
| for size in [1000, 5000].iter() { | ||||||||||
| let mut rng = thread_rng(); | ||||||||||
| let points: Vec<Point2D> = (0..*size) | ||||||||||
| .map(|_| Point2D::new(rng.gen_range(0.0..100.0), rng.gen_range(0.0..100.0))) | ||||||||||
| .collect(); | ||||||||||
|
|
||||||||||
| group.bench_with_input(BenchmarkId::new("graham_scan", size), &points, |b, pts| { | ||||||||||
| b.iter(|| { | ||||||||||
| let mut p = pts.clone(); | ||||||||||
| GrahamScan::new(black_box(&mut p)); | ||||||||||
|
Comment on lines
+17
to
+18
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
Suggested change
|
||||||||||
| }); | ||||||||||
| }); | ||||||||||
| } | ||||||||||
| group.finish(); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| criterion_group!(benches, geometry_benchmark); | ||||||||||
| criterion_main!(benches); | ||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
rnganddatavariables are created but never used within the benchmark loop. This dead code should be removed to improve clarity.