Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "orx-fixed-vec"
version = "3.17.0"
version = "3.18.0"
edition = "2024"
authors = ["orxfun <orx.ugur.arikan@gmail.com>"]
description = "An efficient fixed capacity vector with pinned element guarantees."
Expand All @@ -12,17 +12,14 @@ categories = ["data-structures", "rust-patterns", "no-std"]
[dependencies]
orx-iterable = { version = "1.3.0", default-features = false }
orx-pseudo-default = { version = "2.1.0", default-features = false }
orx-pinned-vec = { version = "3.16.0", default-features = false }
orx-concurrent-iter = { version = "2.1.0", default-features = false }
orx-pinned-vec = { version = "3.17.0", default-features = false }
orx-concurrent-iter = { version = "2.3.0", default-features = false }

[[bench]]
name = "par_collect_map_filter_owned"
name = "random_access"
harness = false

[dev-dependencies]
clap = { version = "4.5.38", features = ["derive"] }
criterion = "0.6.0"
rand = "0.9"
rand_chacha = "0.9"
orx-parallel = { version = "2.0.1", default-features = false }
rayon = { version = "1.10.0", default-features = false }
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ This means that computations over the fixed vector can be efficiently paralleliz
* `fixed_vec.par()` returns a parallel iterator over references to its elements, and
* `fixed_vec.into_par()` consumes the vector and returns a parallel iterator of the owned elements.

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

## Examples

Expand Down
216 changes: 108 additions & 108 deletions benches/par_collect_map_filter_owned.rs
Original file line number Diff line number Diff line change
@@ -1,108 +1,108 @@
use criterion::{BenchmarkId, Criterion, criterion_group, criterion_main};
use orx_fixed_vec::*;
use orx_parallel::*;
use rand::prelude::*;
use rand_chacha::ChaCha8Rng;
use std::hint::black_box;

const TEST_LARGE_OUTPUT: bool = false;

const LARGE_OUTPUT_LEN: usize = match TEST_LARGE_OUTPUT {
true => 64,
false => 0,
};
const SEED: u64 = 5426;
const FIB_UPPER_BOUND: u32 = 201;

#[derive(Debug, PartialEq, Eq, PartialOrd, Ord)]
struct Output {
name: String,
numbers: [i64; LARGE_OUTPUT_LEN],
}

fn map(idx: usize) -> Output {
let prefix = match idx % 7 {
0 => "zero-",
3 => "three-",
_ => "sth-",
};
let fib = fibonacci(&(idx as u32));
let name = format!("{}-fib-{}", prefix, fib);

let mut numbers = [0i64; LARGE_OUTPUT_LEN];
for (i, x) in numbers.iter_mut().enumerate() {
*x = match (idx * 7 + i) % 3 {
0 => idx as i64 + i as i64,
_ => idx as i64 - i as i64,
};
}

Output { name, numbers }
}

fn filter(output: &Output) -> bool {
let last_char = output.name.chars().last().unwrap();
let last_digit: u32 = last_char.to_string().parse().unwrap();
last_digit < 4
}

fn fibonacci(n: &u32) -> u32 {
let mut a = 0;
let mut b = 1;
for _ in 0..*n {
let c = a + b;
a = b;
b = c;
}
a
}

fn input(len: usize) -> impl Iterator<Item = usize> {
let mut rng = ChaCha8Rng::seed_from_u64(SEED);
(0..len).map(move |_| rng.random_range(0..FIB_UPPER_BOUND) as usize)
}

fn seq(inputs: Vec<usize>) -> Vec<Output> {
inputs.into_iter().map(map).filter(filter).collect()
}

fn par_over_vec(inputs: Vec<usize>) -> Vec<Output> {
inputs.into_par().map(map).filter(filter).collect()
}

fn par_over_fixed_vec(inputs: FixedVec<usize>) -> Vec<Output> {
inputs.into_par().map(map).filter(filter).collect()
}

fn run(c: &mut Criterion) {
let treatments = [65_536, 65_536 * 4];

#[allow(unused_mut)]
let mut group = c.benchmark_group("par_collect_map_filter_owned");

for n in &treatments {
let expected = seq(input(*n).collect());

let input_fixed = || input(*n).collect::<FixedVec<_>>();

group.bench_with_input(BenchmarkId::new("seq", n), n, |b, _| {
assert_eq!(&expected, &seq(input(*n).collect()));
b.iter(|| seq(black_box(input(*n).collect())))
});

group.bench_with_input(BenchmarkId::new("par_over_vec", n), n, |b, _| {
assert_eq!(&expected, &par_over_vec(input(*n).collect()));
b.iter(|| par_over_vec(black_box(input(*n).collect())))
});

group.bench_with_input(BenchmarkId::new("par_over_fixed_vec", n), n, |b, _| {
assert_eq!(&expected, &par_over_fixed_vec(input_fixed()));
b.iter(|| par_over_fixed_vec(black_box(input_fixed())))
});
}

group.finish();
}

criterion_group!(benches, run);
criterion_main!(benches);
// use criterion::{BenchmarkId, Criterion, criterion_group, criterion_main};
// use orx_fixed_vec::*;
// use orx_parallel::*;
// use rand::prelude::*;
// use rand_chacha::ChaCha8Rng;
// use std::hint::black_box;

// const TEST_LARGE_OUTPUT: bool = false;

// const LARGE_OUTPUT_LEN: usize = match TEST_LARGE_OUTPUT {
// true => 64,
// false => 0,
// };
// const SEED: u64 = 5426;
// const FIB_UPPER_BOUND: u32 = 201;

// #[derive(Debug, PartialEq, Eq, PartialOrd, Ord)]
// struct Output {
// name: String,
// numbers: [i64; LARGE_OUTPUT_LEN],
// }

// fn map(idx: usize) -> Output {
// let prefix = match idx % 7 {
// 0 => "zero-",
// 3 => "three-",
// _ => "sth-",
// };
// let fib = fibonacci(&(idx as u32));
// let name = format!("{}-fib-{}", prefix, fib);

// let mut numbers = [0i64; LARGE_OUTPUT_LEN];
// for (i, x) in numbers.iter_mut().enumerate() {
// *x = match (idx * 7 + i) % 3 {
// 0 => idx as i64 + i as i64,
// _ => idx as i64 - i as i64,
// };
// }

// Output { name, numbers }
// }

// fn filter(output: &Output) -> bool {
// let last_char = output.name.chars().last().unwrap();
// let last_digit: u32 = last_char.to_string().parse().unwrap();
// last_digit < 4
// }

// fn fibonacci(n: &u32) -> u32 {
// let mut a = 0;
// let mut b = 1;
// for _ in 0..*n {
// let c = a + b;
// a = b;
// b = c;
// }
// a
// }

// fn input(len: usize) -> impl Iterator<Item = usize> {
// let mut rng = ChaCha8Rng::seed_from_u64(SEED);
// (0..len).map(move |_| rng.random_range(0..FIB_UPPER_BOUND) as usize)
// }

// fn seq(inputs: Vec<usize>) -> Vec<Output> {
// inputs.into_iter().map(map).filter(filter).collect()
// }

// fn par_over_vec(inputs: Vec<usize>) -> Vec<Output> {
// inputs.into_par().map(map).filter(filter).collect()
// }

// fn par_over_fixed_vec(inputs: FixedVec<usize>) -> Vec<Output> {
// inputs.into_par().map(map).filter(filter).collect()
// }

// fn run(c: &mut Criterion) {
// let treatments = [65_536, 65_536 * 4];

// #[allow(unused_mut)]
// let mut group = c.benchmark_group("par_collect_map_filter_owned");

// for n in &treatments {
// let expected = seq(input(*n).collect());

// let input_fixed = || input(*n).collect::<FixedVec<_>>();

// group.bench_with_input(BenchmarkId::new("seq", n), n, |b, _| {
// assert_eq!(&expected, &seq(input(*n).collect()));
// b.iter(|| seq(black_box(input(*n).collect())))
// });

// group.bench_with_input(BenchmarkId::new("par_over_vec", n), n, |b, _| {
// assert_eq!(&expected, &par_over_vec(input(*n).collect()));
// b.iter(|| par_over_vec(black_box(input(*n).collect())))
// });

// group.bench_with_input(BenchmarkId::new("par_over_fixed_vec", n), n, |b, _| {
// assert_eq!(&expected, &par_over_fixed_vec(input_fixed()));
// b.iter(|| par_over_fixed_vec(black_box(input_fixed())))
// });
// }

// group.finish();
// }

// criterion_group!(benches, run);
// criterion_main!(benches);
Loading