-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
43 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright (c) 2024 Xu Shaohua <[email protected]>. All rights reserved. | ||
// Use of this source is governed by General Public License that can be found | ||
// in the LICENSE file. | ||
|
||
use criterion::{criterion_group, criterion_main, Criterion}; | ||
|
||
use sort::shell_sort::shell_sort; | ||
use sort::util::random_ints; | ||
|
||
fn criterion_benchmark(c: &mut Criterion) { | ||
for exp in 1..5 { | ||
let len: usize = 2 * 10_usize.pow(exp); | ||
let arr = random_ints(len).expect("Failed to generate random integers"); | ||
let title1 = format!("std_sort_for_shell_sort {len}"); | ||
let title2 = format!("shell_sort {len}"); | ||
let mut arr_sorted = arr.clone(); | ||
arr_sorted.sort(); | ||
|
||
c.bench_function(&title1, |b| { | ||
b.iter(|| { | ||
let mut arr1 = arr.clone(); | ||
arr1.sort(); | ||
assert_eq!(arr1, arr_sorted); | ||
}) | ||
}); | ||
c.bench_function(&title2, |b| { | ||
b.iter(|| { | ||
let mut arr2 = arr.clone(); | ||
shell_sort(&mut arr2); | ||
assert_eq!(arr2, arr_sorted); | ||
}) | ||
}); | ||
} | ||
} | ||
|
||
criterion_group!(benches, criterion_benchmark); | ||
criterion_main!(benches); |
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