Compare commits
4 commits
d8f34487dc
...
1431af6f51
Author | SHA1 | Date | |
---|---|---|---|
|
1431af6f51 | ||
|
501179f5fd | ||
|
f1e158fb4d | ||
|
2dc56ba47a |
6 changed files with 2036 additions and 10 deletions
15
README.md
15
README.md
|
@ -59,3 +59,18 @@ algorithms in Rust and benchmark them. Let the battle begin.
|
|||
|
||||
[rust]: https://www.rust-lang.org/
|
||||
[gnuplot]: http://www.gnuplot.info/
|
||||
|
||||
|
||||
## Algorithms
|
||||
|
||||
- `single thread`: No multi-threading or any optimization of any kind. Used as
|
||||
a reference.
|
||||
- `rayon`: Multi-threading provided by the `rayon` crate, but no optimization
|
||||
of any kind. Used as a reference.
|
||||
- `rayon sorted`: Multi-threading provided by the `rayon` crate. Tasks are
|
||||
sorted so the shortest ones are executed first.
|
||||
- `rayon sorted reverse`: Multi-threading provided by the `rayon` crate. Tasks
|
||||
are sorted so the longest ones are executed first. This should behave as an
|
||||
[LPT][lpt].
|
||||
|
||||
[lpt]: https://en.wikipedia.org/wiki/Longest-processing-time-first_scheduling
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
|
||||
use rust_job_scheduling::algorithm::*;
|
||||
use rust_job_scheduling::data::SMALL;
|
||||
use rust_job_scheduling::data::*;
|
||||
use rust_job_scheduling::Task;
|
||||
|
||||
const TEST_DATA: &[(&str, &[Task])] = &[("small", SMALL)];
|
||||
const TEST_DATA: &[(&str, &[Task])] = &[("10 tasks", T_10), ("500 tasks", T_500)];
|
||||
const TEST_FUNCS: &[(&str, &dyn Fn(&[Task]))] = &[
|
||||
("single thread", &single_thread),
|
||||
("rayon", &rayon),
|
||||
("rayon sorted", &rayon_sorted),
|
||||
("rayon sorted reverse", &rayon_sorted_reverse),
|
||||
];
|
||||
|
||||
fn job_scheduling_benchmark(c: &mut Criterion) {
|
||||
|
|
|
@ -7,6 +7,14 @@ pub fn rayon(data: &[Task]) {
|
|||
|
||||
pub fn rayon_sorted(data: &[Task]) {
|
||||
let mut data = data.to_vec();
|
||||
// Shortest tasks first
|
||||
data.sort();
|
||||
rayon(&data)
|
||||
rayon(&data);
|
||||
}
|
||||
|
||||
pub fn rayon_sorted_reverse(data: &[Task]) {
|
||||
let mut data = data.to_vec();
|
||||
// Longest tasks first
|
||||
data.sort_by(|a, b| a.cmp(b).reverse());
|
||||
rayon(&data);
|
||||
}
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
mod small;
|
||||
mod t10;
|
||||
mod t500;
|
||||
|
||||
pub use small::SMALL;
|
||||
pub use t10::T_10;
|
||||
pub use t500::T_500;
|
||||
|
|
|
@ -1,10 +1,6 @@
|
|||
use crate::Task;
|
||||
|
||||
pub const SMALL: &[Task] = &[
|
||||
Task {
|
||||
data: b"eb17a235c386039c41c65bf5",
|
||||
cost: 500,
|
||||
},
|
||||
pub const T_10: &[Task] = &[
|
||||
Task {
|
||||
data: b"df33fd171cd4d311775ebe76",
|
||||
cost: 100,
|
2004
src/data/t500.rs
Normal file
2004
src/data/t500.rs
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue