Skip to content

Commit 9383c35

Browse files
Add f64 sum benchmarks (#8367)
Adds `f64` cases to the `aggregate_sum` and `aggregate_grouped` benchmarks in `vortex-array`, to establish a baseline before changing float summation to Kahan (Neumaier) compensated summation. Signed-off-by: Dimitar Dimitrov <dimitar@spiraldb.com>
1 parent d021152 commit 9383c35

2 files changed

Lines changed: 82 additions & 0 deletions

File tree

vortex-array/benches/aggregate_grouped.rs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,36 @@ fn i32_clustered_nulls_input() -> ArrayRef {
9898
)
9999
}
100100

101+
fn f64_all_valid_input() -> ArrayRef {
102+
let group_sizes = random_group_sizes();
103+
let element_count = total_element_count(&group_sizes);
104+
let mut rng = StdRng::seed_from_u64(GROUP_SIZE_SEED);
105+
let values: Buffer<f64> = (0..element_count)
106+
.map(|_| rng.random_range(-1000.0..1000.0))
107+
.collect();
108+
contiguous_list_view(
109+
PrimitiveArray::new(values, Validity::NonNullable).into_array(),
110+
&group_sizes,
111+
)
112+
}
113+
114+
fn f64_clustered_nulls_input() -> ArrayRef {
115+
let group_sizes = random_group_sizes();
116+
let element_count = total_element_count(&group_sizes);
117+
let mut rng = StdRng::seed_from_u64(GROUP_SIZE_SEED);
118+
let values = (0..element_count).map(|i| {
119+
if (i / 16) % 8 == 0 {
120+
None
121+
} else {
122+
Some(rng.random_range(-1000.0f64..1000.0))
123+
}
124+
});
125+
contiguous_list_view(
126+
PrimitiveArray::from_option_iter(values).into_array(),
127+
&group_sizes,
128+
)
129+
}
130+
101131
fn varbinview_input() -> ArrayRef {
102132
let group_sizes = random_group_sizes();
103133
let element_count = total_element_count(&group_sizes);
@@ -144,6 +174,22 @@ fn sum_i32_clustered_nulls(bencher: Bencher) {
144174
.bench_refs(|input| grouped_accumulator(input, Sum));
145175
}
146176

177+
#[divan::bench]
178+
fn sum_f64_all_valid(bencher: Bencher) {
179+
let input = f64_all_valid_input();
180+
bencher
181+
.with_inputs(|| &input)
182+
.bench_refs(|input| grouped_accumulator(input, Sum));
183+
}
184+
185+
#[divan::bench]
186+
fn sum_f64_clustered_nulls(bencher: Bencher) {
187+
let input = f64_clustered_nulls_input();
188+
bencher
189+
.with_inputs(|| &input)
190+
.bench_refs(|input| grouped_accumulator(input, Sum));
191+
}
192+
147193
#[divan::bench]
148194
fn count_i32_clustered_nulls(bencher: Bencher) {
149195
let input = i32_clustered_nulls_input();

vortex-array/benches/aggregate_sum.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,42 @@ fn sum_i64(bencher: Bencher) {
6363
.bench_refs(|(a, ctx)| a.statistics().compute_as::<i64>(Stat::Sum, ctx));
6464
}
6565

66+
#[divan::bench]
67+
fn sum_f64(bencher: Bencher) {
68+
let mut rng = StdRng::seed_from_u64(6);
69+
let data: Vec<f64> = (0..N).map(|_| rng.random_range(-1000.0..1000.0)).collect();
70+
bencher
71+
.with_inputs(|| {
72+
(
73+
PrimitiveArray::from_iter(data.iter().copied()).into_array(),
74+
SESSION.create_execution_ctx(),
75+
)
76+
})
77+
.bench_refs(|(a, ctx)| a.statistics().compute_as::<f64>(Stat::Sum, ctx));
78+
}
79+
80+
#[divan::bench]
81+
fn sum_f64_nulls_clustered(bencher: Bencher) {
82+
let mut rng = StdRng::seed_from_u64(7);
83+
let data: Vec<Option<f64>> = (0..N)
84+
.map(|i| {
85+
if (i / 64) % 10 == 0 {
86+
None
87+
} else {
88+
Some(rng.random_range(-1000.0..1000.0))
89+
}
90+
})
91+
.collect();
92+
bencher
93+
.with_inputs(|| {
94+
(
95+
PrimitiveArray::from_option_iter(data.iter().copied()).into_array(),
96+
SESSION.create_execution_ctx(),
97+
)
98+
})
99+
.bench_refs(|(a, ctx)| a.statistics().compute_as::<f64>(Stat::Sum, ctx));
100+
}
101+
66102
// Clustered nulls: long runs of valid values broken up by occasional null blocks. This is the
67103
// case the run-based valid path is expected to accelerate.
68104
#[divan::bench]

0 commit comments

Comments
 (0)