Compare commits

..

4 commits

Author SHA1 Message Date
Rodolphe Bréard
1431af6f51 Describe the algorithms 2024-10-30 22:24:26 +01:00
Rodolphe Bréard
501179f5fd Add the rayon_sorted_reverse algorithm 2024-10-30 22:23:55 +01:00
Rodolphe Bréard
f1e158fb4d Add a new data set of 500 tasks 2024-10-30 21:55:11 +01:00
Rodolphe Bréard
2dc56ba47a Rename the small data set 2024-10-30 21:54:25 +01:00
6 changed files with 2036 additions and 10 deletions

View file

@ -59,3 +59,18 @@ algorithms in Rust and benchmark them. Let the battle begin.
[rust]: https://www.rust-lang.org/ [rust]: https://www.rust-lang.org/
[gnuplot]: http://www.gnuplot.info/ [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

View file

@ -1,13 +1,14 @@
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion}; use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
use rust_job_scheduling::algorithm::*; use rust_job_scheduling::algorithm::*;
use rust_job_scheduling::data::SMALL; use rust_job_scheduling::data::*;
use rust_job_scheduling::Task; 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]))] = &[ const TEST_FUNCS: &[(&str, &dyn Fn(&[Task]))] = &[
("single thread", &single_thread), ("single thread", &single_thread),
("rayon", &rayon), ("rayon", &rayon),
("rayon sorted", &rayon_sorted), ("rayon sorted", &rayon_sorted),
("rayon sorted reverse", &rayon_sorted_reverse),
]; ];
fn job_scheduling_benchmark(c: &mut Criterion) { fn job_scheduling_benchmark(c: &mut Criterion) {

View file

@ -7,6 +7,14 @@ pub fn rayon(data: &[Task]) {
pub fn rayon_sorted(data: &[Task]) { pub fn rayon_sorted(data: &[Task]) {
let mut data = data.to_vec(); let mut data = data.to_vec();
// Shortest tasks first
data.sort(); 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);
} }

View file

@ -1,3 +1,5 @@
mod small; mod t10;
mod t500;
pub use small::SMALL; pub use t10::T_10;
pub use t500::T_500;

View file

@ -1,10 +1,6 @@
use crate::Task; use crate::Task;
pub const SMALL: &[Task] = &[ pub const T_10: &[Task] = &[
Task {
data: b"eb17a235c386039c41c65bf5",
cost: 500,
},
Task { Task {
data: b"df33fd171cd4d311775ebe76", data: b"df33fd171cd4d311775ebe76",
cost: 100, cost: 100,

2004
src/data/t500.rs Normal file

File diff suppressed because it is too large Load diff