Skip to content

Commit 9df466e

Browse files
authored
Merge pull request #84 from orxfun/new-concurrent-iter-version
New concurrent iter version
2 parents 6c0d040 + 600ecf0 commit 9df466e

File tree

26 files changed

+1126
-388
lines changed

26 files changed

+1126
-388
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
/target
22
/Cargo.lock
3+
4+
debug/
5+
target/

Cargo.toml

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "orx-split-vec"
3-
version = "3.17.0"
3+
version = "3.18.0"
44
edition = "2024"
55
authors = ["orxfun <[email protected]>"]
66
description = "An efficient dynamic capacity vector with pinned element guarantees."
@@ -12,19 +12,16 @@ categories = ["data-structures", "rust-patterns", "no-std"]
1212
[dependencies]
1313
orx-iterable = { version = "1.3.0", default-features = false }
1414
orx-pseudo-default = { version = "2.1.0", default-features = false }
15-
orx-pinned-vec = { version = "3.16.0", default-features = false }
16-
orx-concurrent-iter = { version = "2.1.0", default-features = false }
15+
orx-pinned-vec = { version = "3.17.0", default-features = false }
16+
orx-concurrent-iter = { version = "2.3.0", default-features = false }
1717

1818
[[bench]]
19-
name = "par_collect_map_filter_ref"
19+
name = "serial_access"
2020
harness = false
2121

2222
[dev-dependencies]
23-
clap = { version = "4.5.38", features = ["derive"] }
2423
criterion = "0.6.0"
2524
rand = { version = "0.9", default-features = false }
2625
rand_chacha = { version = "0.9", default-features = false }
2726
test-case = "3.3.1"
2827
orx-concurrent-bag = "2.12.0"
29-
orx-parallel = { version = "2.0.1", default-features = false }
30-
rayon = { version = "1.10.0", default-features = false }

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ This means that computations over the split vector can be efficiently paralleliz
7474
* `split_vec.par()` returns a parallel iterator over references to its elements, and
7575
* `split_vec.into_par()` consumes the vector and returns a parallel iterator of the owned elements.
7676

77-
You may find demonstrations in [`demo_parallelization`](https://github.com/orxfun/orx-split-vec/blob/main/examples/demo_parallelization.rs) and [`bench_parallelization`](https://github.com/orxfun/orx-split-vec/blob/main/examples/bench_parallelization.rs) examples.
77+
You may find demonstrations in [`demo_parallelization`](https://github.com/orxfun/orx-split-vec/blob/main/examples/demo_parallelization) and [`bench_parallelization`](https://github.com/orxfun/orx-split-vec/blob/main/examples/bench_parallelization) examples.
7878

7979

8080
## Examples
Lines changed: 138 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -1,138 +1,138 @@
1-
use criterion::{BenchmarkId, Criterion, criterion_group, criterion_main};
2-
use orx_parallel::*;
3-
use orx_split_vec::*;
4-
use rand::prelude::*;
5-
use rand_chacha::ChaCha8Rng;
6-
use std::hint::black_box;
7-
8-
const TEST_LARGE_OUTPUT: bool = false;
9-
10-
const LARGE_OUTPUT_LEN: usize = match TEST_LARGE_OUTPUT {
11-
true => 64,
12-
false => 0,
13-
};
14-
const SEED: u64 = 5426;
15-
const FIB_UPPER_BOUND: u32 = 201;
16-
17-
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord)]
18-
struct Output {
19-
name: String,
20-
numbers: [i64; LARGE_OUTPUT_LEN],
21-
}
22-
23-
fn map(idx: usize) -> Output {
24-
let prefix = match idx % 7 {
25-
0 => "zero-",
26-
3 => "three-",
27-
_ => "sth-",
28-
};
29-
let fib = fibonacci(&(idx as u32));
30-
let name = format!("{}-fib-{}", prefix, fib);
31-
32-
let mut numbers = [0i64; LARGE_OUTPUT_LEN];
33-
for (i, x) in numbers.iter_mut().enumerate() {
34-
*x = match (idx * 7 + i) % 3 {
35-
0 => idx as i64 + i as i64,
36-
_ => idx as i64 - i as i64,
37-
};
38-
}
39-
40-
Output { name, numbers }
41-
}
42-
43-
fn filter(output: &Output) -> bool {
44-
let last_char = output.name.chars().last().unwrap();
45-
let last_digit: u32 = last_char.to_string().parse().unwrap();
46-
last_digit < 4
47-
}
48-
49-
fn fibonacci(n: &u32) -> u32 {
50-
let mut a = 0;
51-
let mut b = 1;
52-
for _ in 0..*n {
53-
let c = a + b;
54-
a = b;
55-
b = c;
56-
}
57-
a
58-
}
59-
60-
fn input(len: usize) -> impl Iterator<Item = usize> {
61-
let mut rng = ChaCha8Rng::seed_from_u64(SEED);
62-
(0..len).map(move |_| rng.random_range(0..FIB_UPPER_BOUND) as usize)
63-
}
64-
65-
fn seq(inputs: Vec<usize>) -> Vec<Output> {
66-
inputs.into_iter().map(map).filter(filter).collect()
67-
}
68-
69-
fn par_over_vec(inputs: Vec<usize>) -> Vec<Output> {
70-
inputs.into_par().map(map).filter(filter).collect()
71-
}
72-
73-
fn par_over_split_vec<G: ParGrowth>(inputs: SplitVec<usize, G>) -> Vec<Output> {
74-
inputs.into_par().map(map).filter(filter).collect()
75-
}
76-
77-
fn run(c: &mut Criterion) {
78-
let treatments = [65_536, 65_536 * 4];
79-
80-
#[allow(unused_mut)]
81-
let mut group = c.benchmark_group("par_collect_map_filter_owned");
82-
83-
for n in &treatments {
84-
let expected = seq(input(*n).collect());
85-
86-
let input_doubling = || input(*n).collect::<SplitVec<_, Doubling>>();
87-
88-
let input_recursive = || input(*n).collect::<SplitVec<_, Recursive>>();
89-
90-
let input_linear = || {
91-
let mut input_linear = SplitVec::with_linear_growth(10);
92-
input_linear.extend(input(*n));
93-
input_linear
94-
};
95-
96-
group.bench_with_input(BenchmarkId::new("seq", n), n, |b, _| {
97-
assert_eq!(&expected, &seq(input(*n).collect()));
98-
b.iter(|| seq(black_box(input(*n).collect())))
99-
});
100-
101-
group.bench_with_input(BenchmarkId::new("par_over_vec", n), n, |b, _| {
102-
assert_eq!(&expected, &par_over_vec(input(*n).collect()));
103-
b.iter(|| par_over_vec(black_box(input(*n).collect())))
104-
});
105-
106-
group.bench_with_input(
107-
BenchmarkId::new("par_over_split_vec_doubling", n),
108-
n,
109-
|b, _| {
110-
assert_eq!(&expected, &par_over_split_vec(input_doubling()));
111-
b.iter(|| par_over_split_vec(black_box(input_doubling())))
112-
},
113-
);
114-
115-
group.bench_with_input(
116-
BenchmarkId::new("par_over_split_vec_linear", n),
117-
n,
118-
|b, _| {
119-
assert_eq!(&expected, &par_over_split_vec(input_linear()));
120-
b.iter(|| par_over_split_vec(black_box(input_linear())))
121-
},
122-
);
123-
124-
group.bench_with_input(
125-
BenchmarkId::new("par_over_split_vec_recursive", n),
126-
n,
127-
|b, _| {
128-
assert_eq!(&expected, &par_over_split_vec(input_recursive()));
129-
b.iter(|| par_over_split_vec(black_box(input_recursive())))
130-
},
131-
);
132-
}
133-
134-
group.finish();
135-
}
136-
137-
criterion_group!(benches, run);
138-
criterion_main!(benches);
1+
// use criterion::{BenchmarkId, Criterion, criterion_group, criterion_main};
2+
// use orx_parallel::*;
3+
// use orx_split_vec::*;
4+
// use rand::prelude::*;
5+
// use rand_chacha::ChaCha8Rng;
6+
// use std::hint::black_box;
7+
8+
// const TEST_LARGE_OUTPUT: bool = false;
9+
10+
// const LARGE_OUTPUT_LEN: usize = match TEST_LARGE_OUTPUT {
11+
// true => 64,
12+
// false => 0,
13+
// };
14+
// const SEED: u64 = 5426;
15+
// const FIB_UPPER_BOUND: u32 = 201;
16+
17+
// #[derive(Debug, PartialEq, Eq, PartialOrd, Ord)]
18+
// struct Output {
19+
// name: String,
20+
// numbers: [i64; LARGE_OUTPUT_LEN],
21+
// }
22+
23+
// fn map(idx: usize) -> Output {
24+
// let prefix = match idx % 7 {
25+
// 0 => "zero-",
26+
// 3 => "three-",
27+
// _ => "sth-",
28+
// };
29+
// let fib = fibonacci(&(idx as u32));
30+
// let name = format!("{}-fib-{}", prefix, fib);
31+
32+
// let mut numbers = [0i64; LARGE_OUTPUT_LEN];
33+
// for (i, x) in numbers.iter_mut().enumerate() {
34+
// *x = match (idx * 7 + i) % 3 {
35+
// 0 => idx as i64 + i as i64,
36+
// _ => idx as i64 - i as i64,
37+
// };
38+
// }
39+
40+
// Output { name, numbers }
41+
// }
42+
43+
// fn filter(output: &Output) -> bool {
44+
// let last_char = output.name.chars().last().unwrap();
45+
// let last_digit: u32 = last_char.to_string().parse().unwrap();
46+
// last_digit < 4
47+
// }
48+
49+
// fn fibonacci(n: &u32) -> u32 {
50+
// let mut a = 0;
51+
// let mut b = 1;
52+
// for _ in 0..*n {
53+
// let c = a + b;
54+
// a = b;
55+
// b = c;
56+
// }
57+
// a
58+
// }
59+
60+
// fn input(len: usize) -> impl Iterator<Item = usize> {
61+
// let mut rng = ChaCha8Rng::seed_from_u64(SEED);
62+
// (0..len).map(move |_| rng.random_range(0..FIB_UPPER_BOUND) as usize)
63+
// }
64+
65+
// fn seq(inputs: Vec<usize>) -> Vec<Output> {
66+
// inputs.into_iter().map(map).filter(filter).collect()
67+
// }
68+
69+
// fn par_over_vec(inputs: Vec<usize>) -> Vec<Output> {
70+
// inputs.into_par().map(map).filter(filter).collect()
71+
// }
72+
73+
// fn par_over_split_vec<G: ParGrowth>(inputs: SplitVec<usize, G>) -> Vec<Output> {
74+
// inputs.into_par().map(map).filter(filter).collect()
75+
// }
76+
77+
// fn run(c: &mut Criterion) {
78+
// let treatments = [65_536, 65_536 * 4];
79+
80+
// #[allow(unused_mut)]
81+
// let mut group = c.benchmark_group("par_collect_map_filter_owned");
82+
83+
// for n in &treatments {
84+
// let expected = seq(input(*n).collect());
85+
86+
// let input_doubling = || input(*n).collect::<SplitVec<_, Doubling>>();
87+
88+
// let input_recursive = || input(*n).collect::<SplitVec<_, Recursive>>();
89+
90+
// let input_linear = || {
91+
// let mut input_linear = SplitVec::with_linear_growth(10);
92+
// input_linear.extend(input(*n));
93+
// input_linear
94+
// };
95+
96+
// group.bench_with_input(BenchmarkId::new("seq", n), n, |b, _| {
97+
// assert_eq!(&expected, &seq(input(*n).collect()));
98+
// b.iter(|| seq(black_box(input(*n).collect())))
99+
// });
100+
101+
// group.bench_with_input(BenchmarkId::new("par_over_vec", n), n, |b, _| {
102+
// assert_eq!(&expected, &par_over_vec(input(*n).collect()));
103+
// b.iter(|| par_over_vec(black_box(input(*n).collect())))
104+
// });
105+
106+
// group.bench_with_input(
107+
// BenchmarkId::new("par_over_split_vec_doubling", n),
108+
// n,
109+
// |b, _| {
110+
// assert_eq!(&expected, &par_over_split_vec(input_doubling()));
111+
// b.iter(|| par_over_split_vec(black_box(input_doubling())))
112+
// },
113+
// );
114+
115+
// group.bench_with_input(
116+
// BenchmarkId::new("par_over_split_vec_linear", n),
117+
// n,
118+
// |b, _| {
119+
// assert_eq!(&expected, &par_over_split_vec(input_linear()));
120+
// b.iter(|| par_over_split_vec(black_box(input_linear())))
121+
// },
122+
// );
123+
124+
// group.bench_with_input(
125+
// BenchmarkId::new("par_over_split_vec_recursive", n),
126+
// n,
127+
// |b, _| {
128+
// assert_eq!(&expected, &par_over_split_vec(input_recursive()));
129+
// b.iter(|| par_over_split_vec(black_box(input_recursive())))
130+
// },
131+
// );
132+
// }
133+
134+
// group.finish();
135+
// }
136+
137+
// criterion_group!(benches, run);
138+
// criterion_main!(benches);

0 commit comments

Comments
 (0)