-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added benchmark, edited Cargo and documentation
- Loading branch information
Showing
3 changed files
with
86 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,23 +4,24 @@ version = "1.1.0" | |
authors = ["flakusha <[email protected]>"] | ||
edition = "2018" | ||
repository = "https://github.com/flakusha/rust_sorting" | ||
description = "Collection of sorting algorithms implemented in Rust" | ||
|
||
keywords = ["sort", "sorting", "library"] | ||
categories = ["algorithms"] | ||
|
||
license = "MIT" | ||
readme = "README.md" | ||
|
||
autobenches = false | ||
|
||
include = [ | ||
"/src/**", | ||
"/bench/**", | ||
] | ||
# See more keys and their definitions at | ||
# https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
|
||
[dev-dependencies] | ||
rand = "^0.7.3" | ||
rand = "^0.7.3" | ||
criterion = "^0.3" | ||
|
||
[[bench]] | ||
name = "sort_benchmark" | ||
harness = false |
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,59 @@ | ||
// #[macro_use] | ||
use criterion::{ | ||
criterion_group, criterion_main, | ||
Criterion, Bencher, ParameterizedBenchmark | ||
}; | ||
use rand::prelude::*; | ||
|
||
fn get_random_vec(n: usize) -> Vec<usize> { | ||
let mut rng: StdRng = StdRng::seed_from_u64(42); | ||
let mut vec: Vec<usize> = (0..n).collect(); | ||
vec.shuffle(&mut rng); | ||
vec | ||
} | ||
|
||
macro_rules! create_bench_function { | ||
($x:ident) => { | ||
|b: &mut Bencher, n: &usize| { | ||
let s = get_random_vec(*n); | ||
b.iter(|| sorting_rs::$x(&mut s.clone())); | ||
} | ||
}; | ||
} | ||
|
||
macro_rules! create_bench { | ||
($p: expr, $f: ident, $($s: ident), *) => { | ||
ParameterizedBenchmark::new(stringify!($f), | ||
create_bench_function!($f), $p) | ||
$(.with_function(stringify!($s), create_bench_function!($s)))* | ||
} | ||
} | ||
|
||
fn bench(c: &mut Criterion) { | ||
let sizes: Vec<usize> = vec![10, 100, 1000, 10_000, 100_000, /*1_000_000, | ||
10_000_000*/]; | ||
|
||
let benchmark = create_bench! { | ||
sizes, | ||
bubble_sort, | ||
cocktail_sort, | ||
comb_sort, | ||
gnome_sort, | ||
heap_sort, | ||
heap_bottom_up_sort, | ||
insertion_sort, | ||
merge_sort, | ||
oddeven_sort, | ||
quick_sort, | ||
selection_sort, | ||
shell_sort, | ||
slow_sort, | ||
// smooth_sort, | ||
stooge_sort | ||
}; | ||
|
||
c.bench("sort_bench", benchmark); | ||
} | ||
|
||
criterion_group!(benches, bench); | ||
criterion_main!(benches); |