-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from orxfun/major-refactoring-v2.0
major refactoring
- Loading branch information
Showing
35 changed files
with
3,232 additions
and
3,849 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 |
---|---|---|
@@ -1,24 +1,24 @@ | ||
[package] | ||
name = "orx-linked-list" | ||
version = "1.0.0" | ||
version = "2.0.0" | ||
edition = "2021" | ||
authors = ["orxfun <[email protected]>"] | ||
description = "An efficient doubly linked list using regular & references with a focus on better cache locality avoiding heap allocations by smart pointers." | ||
description = "An efficient and recursive singly and doubly linked list implementation." | ||
license = "MIT" | ||
repository = "https://github.com/orxfun/orx-linked-list/" | ||
keywords = ["linked", "list", "vec", "array", "pinned"] | ||
categories = ["data-structures", "rust-patterns"] | ||
|
||
[dependencies] | ||
orx-imp-vec = "1.0" | ||
orx-split-vec = "1.2" | ||
|
||
orx-selfref-col = "1.0" | ||
orx-split-vec = "2.0" | ||
|
||
[dev-dependencies] | ||
rand = "0.8" | ||
rand_chacha = "0.3" | ||
criterion = { version = "0.5", features = ["html_reports"] } | ||
test-case = "3.3" | ||
|
||
[[bench]] | ||
name = "mutation_ends" | ||
name = "append" | ||
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,104 @@ | ||
use criterion::{ | ||
criterion_group, criterion_main, measurement::WallTime, BenchmarkGroup, BenchmarkId, Criterion, | ||
}; | ||
use rand::prelude::*; | ||
use rand_chacha::ChaCha8Rng; | ||
|
||
#[derive(Clone, Copy)] | ||
enum Action { | ||
PushBack(u32), | ||
PushFront(u32), | ||
} | ||
|
||
fn get_test_data(n: usize) -> Vec<Action> { | ||
let mut rng = ChaCha8Rng::seed_from_u64(6523); | ||
let vec: Vec<_> = (0..n) | ||
.map(|_| match rng.gen::<f32>() { | ||
x if x < 0.5 => Action::PushBack(rng.gen()), | ||
_ => Action::PushFront(rng.gen()), | ||
}) | ||
.collect(); | ||
vec | ||
} | ||
fn get_orx_linked_list(actions: &[Action]) -> orx_linked_list::DoublyLinkedList<u32> { | ||
let mut list = orx_linked_list::DoublyLinkedList::new(); | ||
for action in actions { | ||
match action { | ||
Action::PushBack(x) => list.push_back(*x), | ||
Action::PushFront(x) => list.push_front(*x), | ||
}; | ||
} | ||
list | ||
} | ||
fn get_std_linked_list(actions: &[Action]) -> std::collections::LinkedList<u32> { | ||
let mut list = std::collections::LinkedList::new(); | ||
for action in actions { | ||
match action { | ||
Action::PushBack(x) => list.push_back(*x), | ||
Action::PushFront(x) => list.push_front(*x), | ||
}; | ||
} | ||
list | ||
} | ||
fn get_std_vecdeque(actions: &[Action]) -> std::collections::VecDeque<u32> { | ||
let mut list = std::collections::VecDeque::new(); | ||
for action in actions { | ||
match action { | ||
Action::PushBack(x) => list.push_back(*x), | ||
Action::PushFront(x) => list.push_front(*x), | ||
}; | ||
} | ||
list | ||
} | ||
|
||
// variants | ||
fn bench_orx_linked_list(group: &mut BenchmarkGroup<'_, WallTime>, data: &[Action], n: &usize) { | ||
group.bench_with_input( | ||
BenchmarkId::new("orx_linked_list::DoublyLinkedList", n), | ||
n, | ||
|b, _| { | ||
let mut list = get_orx_linked_list(data); | ||
b.iter(|| list.append_back(get_orx_linked_list(data))) | ||
}, | ||
); | ||
} | ||
|
||
fn bench(c: &mut Criterion) { | ||
let treatments = vec![ | ||
1_024, | ||
1_024 * 4, | ||
1_024 * 16, | ||
1_024 * 16 * 4, | ||
1_024 * 16 * 4 * 4, | ||
]; | ||
|
||
let mut group = c.benchmark_group("append"); | ||
|
||
for n in &treatments { | ||
let data = get_test_data(*n); | ||
|
||
bench_orx_linked_list(&mut group, &data, n); | ||
|
||
group.bench_with_input( | ||
BenchmarkId::new("std::collections::LinkedList", n), | ||
n, | ||
|b, _| { | ||
let mut list = get_std_linked_list(&data); | ||
b.iter(|| list.append(&mut get_std_linked_list(&data))) | ||
}, | ||
); | ||
group.bench_with_input( | ||
BenchmarkId::new("std::collections::VecDeque", n), | ||
n, | ||
|b, _| { | ||
let mut list = get_std_vecdeque(&data); | ||
b.iter(|| list.append(&mut get_std_vecdeque(&data))) | ||
}, | ||
); | ||
} | ||
|
||
group.finish(); | ||
} | ||
|
||
criterion_group!(benches, bench); | ||
criterion_main!(benches); |
Oops, something went wrong.