Skip to content

Commit a3cbea6

Browse files
committed
💪 add FPCS downsampling algorithm
1 parent 7e2f14a commit a3cbea6

File tree

7 files changed

+678
-1
lines changed

7 files changed

+678
-1
lines changed

downsample_rs/Cargo.toml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ license = "MIT"
99
[dependencies]
1010
# TODO: perhaps use polars?
1111
argminmax = { version = "0.6.1", features = ["half"] }
12-
half = { version = "2.3.1", default-features = false , features=["num-traits"], optional = true}
12+
half = { version = "2.3.1", default-features = false, features = [
13+
"num-traits",
14+
], optional = true }
1315
num-traits = { version = "0.2.17", default-features = false }
1416
once_cell = "1"
1517
rayon = { version = "1.8.0", default-features = false }
@@ -35,3 +37,7 @@ harness = false
3537
[[bench]]
3638
name = "bench_minmaxlttb"
3739
harness = false
40+
41+
[[bench]]
42+
name = "bench_fpcs"
43+
harness = false
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
use criterion::{black_box, criterion_group, criterion_main, Criterion};
2+
use dev_utils::{config, utils};
3+
use downsample_rs::fpcs as fpcs_mod;
4+
5+
fn fpcs_f32_random_array_long(c: &mut Criterion) {
6+
let n = config::ARRAY_LENGTH_LONG;
7+
let y = utils::get_random_array::<f32>(n, f32::MIN, f32::MAX);
8+
let x = (0..n).map(|i| i as i32).collect::<Vec<i32>>();
9+
10+
// Non parallel
11+
// --- without x
12+
c.bench_function("fpcs_vanilla_f32", |b| {
13+
b.iter(|| fpcs_mod::vanilla_fpcs_without_x(black_box(y.as_slice()), black_box(2_000)))
14+
});
15+
c.bench_function("fpcs_mm_f32", |b| {
16+
b.iter(|| fpcs_mod::fpcs_without_x(black_box(y.as_slice()), black_box(2_000)))
17+
});
18+
// --- with x
19+
c.bench_function("fpcs_mm_f32_x", |b| {
20+
b.iter(|| {
21+
fpcs_mod::fpcs_with_x(
22+
black_box(x.as_slice()),
23+
black_box(y.as_slice()),
24+
black_box(2_000),
25+
)
26+
})
27+
});
28+
29+
// Parallel
30+
// --- without x
31+
c.bench_function("fpcs_mm_f32_par", |b| {
32+
b.iter(|| fpcs_mod::fpcs_without_x_parallel(black_box(y.as_slice()), black_box(2_000)))
33+
});
34+
// --- with x
35+
c.bench_function("fpcs_mm_f32_x_par", |b| {
36+
b.iter(|| {
37+
fpcs_mod::fpcs_with_x_parallel(
38+
black_box(x.as_slice()),
39+
black_box(y.as_slice()),
40+
black_box(2_000),
41+
)
42+
})
43+
});
44+
}
45+
46+
fn fpcs_f32_random_array_50m(c: &mut Criterion) {
47+
let n = 50_000_000;
48+
let y = utils::get_random_array::<f32>(n, f32::MIN, f32::MAX);
49+
let x = (0..n).map(|i| i as i32).collect::<Vec<i32>>();
50+
51+
// Non parallel
52+
// --- without x
53+
c.bench_function("fpcs_vanilla_50M_f32", |b| {
54+
b.iter(|| fpcs_mod::vanilla_fpcs_without_x(black_box(y.as_slice()), black_box(2_000)))
55+
});
56+
c.bench_function("fpcs_mm_50M_f32", |b| {
57+
b.iter(|| fpcs_mod::fpcs_without_x(black_box(y.as_slice()), black_box(2_000)))
58+
});
59+
// --- with x
60+
c.bench_function("fpcs_mm_50M_f32_x", |b| {
61+
b.iter(|| {
62+
fpcs_mod::fpcs_with_x(
63+
black_box(x.as_slice()),
64+
black_box(y.as_slice()),
65+
black_box(2_000),
66+
)
67+
})
68+
});
69+
// Parallel
70+
// --- without x
71+
c.bench_function("fpcs_mm_50M_f32_par", |b| {
72+
b.iter(|| fpcs_mod::fpcs_without_x_parallel(black_box(y.as_slice()), black_box(2_000)))
73+
});
74+
// --- with x
75+
c.bench_function("fpcs_mm_50M_f32_x_par", |b| {
76+
b.iter(|| {
77+
fpcs_mod::fpcs_with_x_parallel(
78+
black_box(x.as_slice()),
79+
black_box(y.as_slice()),
80+
black_box(2_000),
81+
)
82+
})
83+
});
84+
}
85+
86+
criterion_group!(
87+
benches,
88+
//
89+
fpcs_f32_random_array_long,
90+
fpcs_f32_random_array_50m,
91+
);
92+
criterion_main!(benches);

0 commit comments

Comments
 (0)