Skip to content

Commit 3f49b68

Browse files
authored
chore: turn byte factory macro into function (#5577)
Signed-off-by: Alexander Droste <[email protected]>
1 parent 6e4d7bd commit 3f49b68

File tree

2 files changed

+45
-51
lines changed

2 files changed

+45
-51
lines changed

vortex/benches/common_encoding_tree_throughput.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,15 @@ fn main() {
4646

4747
const NUM_VALUES: u64 = 1_000_000;
4848

49-
// Helper macro to conditionally add counter based on codspeed cfg
50-
macro_rules! with_counter {
51-
($bencher:expr, $bytes:expr) => {{
52-
#[cfg(not(codspeed))]
53-
let bencher = $bencher.counter(BytesCount::new($bytes));
54-
#[cfg(codspeed)]
55-
let bencher = {
56-
let _ = $bytes; // Consume the bytes value to avoid unused variable warning
57-
$bencher
58-
};
59-
bencher
60-
}};
49+
// Helper function to conditionally add counter based on codspeed cfg
50+
fn with_byte_counter<'a, 'b>(bencher: Bencher<'a, 'b>, bytes: u64) -> Bencher<'a, 'b> {
51+
#[cfg(not(codspeed))]
52+
return bencher.counter(BytesCount::new(bytes));
53+
#[cfg(codspeed)]
54+
{
55+
_ = bytes; // Consume the bytes value to avoid unused variable warning.
56+
return bencher;
57+
}
6158
}
6259

6360
// Encoding tree setup functions
@@ -390,7 +387,7 @@ fn decompress(bencher: Bencher, setup_fn: SetupFn) {
390387
let compressed = setup_fn();
391388
let nbytes = compressed.nbytes();
392389

393-
with_counter!(bencher, nbytes)
390+
with_byte_counter(bencher, nbytes)
394391
.with_inputs(|| &compressed)
395392
.bench_refs(|a| a.to_canonical());
396393
}

vortex/benches/single_encoding_throughput.rs

Lines changed: 35 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,15 @@ fn main() {
4040

4141
const NUM_VALUES: u64 = 1_000_000;
4242

43-
// Helper macro to conditionally add counter based on codspeed cfg
44-
macro_rules! with_counter {
45-
($bencher:expr, $bytes:expr) => {{
46-
#[cfg(not(codspeed))]
47-
let bencher = $bencher.counter(BytesCount::new($bytes));
48-
#[cfg(codspeed)]
49-
let bencher = {
50-
let _ = $bytes; // Consume the bytes value to avoid unused variable warning
51-
$bencher
52-
};
53-
bencher
54-
}};
43+
// Helper function to conditionally add counter based on codspeed cfg
44+
fn with_byte_counter<'a, 'b>(bencher: Bencher<'a, 'b>, bytes: u64) -> Bencher<'a, 'b> {
45+
#[cfg(not(codspeed))]
46+
return bencher.counter(BytesCount::new(bytes));
47+
#[cfg(codspeed)]
48+
{
49+
_ = bytes; // Consume the bytes value to avoid unused variable warning.
50+
return bencher;
51+
}
5552
}
5653

5754
// Setup functions
@@ -92,7 +89,7 @@ fn bench_bitpacked_compress_u32(bencher: Bencher) {
9289
let (uint_array, ..) = setup_primitive_arrays();
9390
let bit_width = 8;
9491

95-
with_counter!(bencher, NUM_VALUES * 4)
92+
with_byte_counter(bencher, NUM_VALUES * 4)
9693
.with_inputs(|| uint_array.clone())
9794
.bench_values(|a| unsafe { bitpack_encode_unchecked(a, bit_width).unwrap() });
9895
}
@@ -105,7 +102,7 @@ fn bench_bitpacked_decompress_u32(bencher: Bencher) {
105102
let bit_width = 8;
106103
let compressed = bitpack_encode(&uint_array, bit_width, None).unwrap();
107104

108-
with_counter!(bencher, NUM_VALUES * 4)
105+
with_byte_counter(bencher, NUM_VALUES * 4)
109106
.with_inputs(|| &compressed)
110107
.bench_refs(|a| a.to_canonical());
111108
}
@@ -114,7 +111,7 @@ fn bench_bitpacked_decompress_u32(bencher: Bencher) {
114111
fn bench_runend_compress_u32(bencher: Bencher) {
115112
let (uint_array, ..) = setup_primitive_arrays();
116113

117-
with_counter!(bencher, NUM_VALUES * 4)
114+
with_byte_counter(bencher, NUM_VALUES * 4)
118115
.with_inputs(|| uint_array.clone())
119116
.bench_values(|a| RunEndArray::encode(a.into_array()).unwrap());
120117
}
@@ -124,7 +121,7 @@ fn bench_runend_decompress_u32(bencher: Bencher) {
124121
let (uint_array, ..) = setup_primitive_arrays();
125122
let compressed = RunEndArray::encode(uint_array.into_array()).unwrap();
126123

127-
with_counter!(bencher, NUM_VALUES * 4)
124+
with_byte_counter(bencher, NUM_VALUES * 4)
128125
.with_inputs(|| &compressed)
129126
.bench_refs(|a| a.to_canonical());
130127
}
@@ -133,7 +130,7 @@ fn bench_runend_decompress_u32(bencher: Bencher) {
133130
fn bench_delta_compress_u32(bencher: Bencher) {
134131
let (uint_array, ..) = setup_primitive_arrays();
135132

136-
with_counter!(bencher, NUM_VALUES * 4)
133+
with_byte_counter(bencher, NUM_VALUES * 4)
137134
.with_inputs(|| &uint_array)
138135
.bench_refs(|a| {
139136
let (bases, deltas) = delta_compress(a).unwrap();
@@ -149,7 +146,7 @@ fn bench_delta_decompress_u32(bencher: Bencher) {
149146
let compressed =
150147
DeltaArray::try_from_delta_compress_parts(bases.into_array(), deltas.into_array()).unwrap();
151148

152-
with_counter!(bencher, NUM_VALUES * 4)
149+
with_byte_counter(bencher, NUM_VALUES * 4)
153150
.with_inputs(|| &compressed)
154151
.bench_refs(|a| a.to_canonical());
155152
}
@@ -158,7 +155,7 @@ fn bench_delta_decompress_u32(bencher: Bencher) {
158155
fn bench_for_compress_i32(bencher: Bencher) {
159156
let (_, int_array, _) = setup_primitive_arrays();
160157

161-
with_counter!(bencher, NUM_VALUES * 4)
158+
with_byte_counter(bencher, NUM_VALUES * 4)
162159
.with_inputs(|| int_array.clone())
163160
.bench_values(|a| FoRArray::encode(a).unwrap());
164161
}
@@ -168,7 +165,7 @@ fn bench_for_decompress_i32(bencher: Bencher) {
168165
let (_, int_array, _) = setup_primitive_arrays();
169166
let compressed = FoRArray::encode(int_array).unwrap();
170167

171-
with_counter!(bencher, NUM_VALUES * 4)
168+
with_byte_counter(bencher, NUM_VALUES * 4)
172169
.with_inputs(|| &compressed)
173170
.bench_refs(|a| a.to_canonical());
174171
}
@@ -177,7 +174,7 @@ fn bench_for_decompress_i32(bencher: Bencher) {
177174
fn bench_dict_compress_u32(bencher: Bencher) {
178175
let (uint_array, ..) = setup_primitive_arrays();
179176

180-
with_counter!(bencher, NUM_VALUES * 4)
177+
with_byte_counter(bencher, NUM_VALUES * 4)
181178
.with_inputs(|| &uint_array)
182179
.bench_refs(|a| dict_encode(a.as_ref()).unwrap());
183180
}
@@ -187,7 +184,7 @@ fn bench_dict_decompress_u32(bencher: Bencher) {
187184
let (uint_array, ..) = setup_primitive_arrays();
188185
let compressed = dict_encode(uint_array.as_ref()).unwrap();
189186

190-
with_counter!(bencher, NUM_VALUES * 4)
187+
with_byte_counter(bencher, NUM_VALUES * 4)
191188
.with_inputs(|| &compressed)
192189
.bench_refs(|a| a.to_canonical());
193190
}
@@ -196,7 +193,7 @@ fn bench_dict_decompress_u32(bencher: Bencher) {
196193
fn bench_zigzag_compress_i32(bencher: Bencher) {
197194
let (_, int_array, _) = setup_primitive_arrays();
198195

199-
with_counter!(bencher, NUM_VALUES * 4)
196+
with_byte_counter(bencher, NUM_VALUES * 4)
200197
.with_inputs(|| int_array.clone())
201198
.bench_values(|a| zigzag_encode(a).unwrap());
202199
}
@@ -206,7 +203,7 @@ fn bench_zigzag_decompress_i32(bencher: Bencher) {
206203
let (_, int_array, _) = setup_primitive_arrays();
207204
let compressed = zigzag_encode(int_array).unwrap();
208205

209-
with_counter!(bencher, NUM_VALUES * 4)
206+
with_byte_counter(bencher, NUM_VALUES * 4)
210207
.with_inputs(|| &compressed)
211208
.bench_refs(|a| a.to_canonical());
212209
}
@@ -215,7 +212,7 @@ fn bench_zigzag_decompress_i32(bencher: Bencher) {
215212
fn bench_alp_compress_f64(bencher: Bencher) {
216213
let (_, _, float_array) = setup_primitive_arrays();
217214

218-
with_counter!(bencher, NUM_VALUES * 8)
215+
with_byte_counter(bencher, NUM_VALUES * 8)
219216
.with_inputs(|| &float_array)
220217
.bench_refs(|a| alp_encode(a, None).unwrap());
221218
}
@@ -225,7 +222,7 @@ fn bench_alp_decompress_f64(bencher: Bencher) {
225222
let (_, _, float_array) = setup_primitive_arrays();
226223
let compressed = alp_encode(&float_array, None).unwrap();
227224

228-
with_counter!(bencher, NUM_VALUES * 8)
225+
with_byte_counter(bencher, NUM_VALUES * 8)
229226
.with_inputs(|| &compressed)
230227
.bench_refs(|a| a.to_canonical());
231228
}
@@ -234,7 +231,7 @@ fn bench_alp_decompress_f64(bencher: Bencher) {
234231
fn bench_alp_rd_compress_f64(bencher: Bencher) {
235232
let (_, _, float_array) = setup_primitive_arrays();
236233

237-
with_counter!(bencher, NUM_VALUES * 8)
234+
with_byte_counter(bencher, NUM_VALUES * 8)
238235
.with_inputs(|| &float_array)
239236
.bench_refs(|a| {
240237
let encoder = RDEncoder::new(a.as_slice::<f64>());
@@ -248,7 +245,7 @@ fn bench_alp_rd_decompress_f64(bencher: Bencher) {
248245
let encoder = RDEncoder::new(float_array.as_slice::<f64>());
249246
let compressed = encoder.encode(&float_array);
250247

251-
with_counter!(bencher, NUM_VALUES * 8)
248+
with_byte_counter(bencher, NUM_VALUES * 8)
252249
.with_inputs(|| &compressed)
253250
.bench_refs(|a| a.to_canonical());
254251
}
@@ -257,7 +254,7 @@ fn bench_alp_rd_decompress_f64(bencher: Bencher) {
257254
fn bench_pcodec_compress_f64(bencher: Bencher) {
258255
let (_, _, float_array) = setup_primitive_arrays();
259256

260-
with_counter!(bencher, NUM_VALUES * 8)
257+
with_byte_counter(bencher, NUM_VALUES * 8)
261258
.with_inputs(|| &float_array)
262259
.bench_refs(|a| PcoArray::from_primitive(a, 3, 0).unwrap());
263260
}
@@ -267,7 +264,7 @@ fn bench_pcodec_decompress_f64(bencher: Bencher) {
267264
let (_, _, float_array) = setup_primitive_arrays();
268265
let compressed = PcoArray::from_primitive(&float_array, 3, 0).unwrap();
269266

270-
with_counter!(bencher, NUM_VALUES * 8)
267+
with_byte_counter(bencher, NUM_VALUES * 8)
271268
.with_inputs(|| &compressed)
272269
.bench_refs(|a| a.to_canonical());
273270
}
@@ -278,7 +275,7 @@ fn bench_zstd_compress_u32(bencher: Bencher) {
278275
let (uint_array, ..) = setup_primitive_arrays();
279276
let array = uint_array.into_array();
280277

281-
with_counter!(bencher, NUM_VALUES * 4)
278+
with_byte_counter(bencher, NUM_VALUES * 4)
282279
.with_inputs(|| array.clone())
283280
.bench_values(|a| ZstdArray::from_array(a, 3, 8192).unwrap());
284281
}
@@ -289,7 +286,7 @@ fn bench_zstd_decompress_u32(bencher: Bencher) {
289286
let (uint_array, ..) = setup_primitive_arrays();
290287
let compressed = ZstdArray::from_array(uint_array.into_array(), 3, 8192).unwrap();
291288

292-
with_counter!(bencher, NUM_VALUES * 4)
289+
with_byte_counter(bencher, NUM_VALUES * 4)
293290
.with_inputs(|| &compressed)
294291
.bench_refs(|a| a.to_canonical());
295292
}
@@ -300,7 +297,7 @@ fn bench_dict_compress_string(bencher: Bencher) {
300297
let varbinview_arr = VarBinViewArray::from_iter_str(gen_varbin_words(1_000_000, 0.00005));
301298
let nbytes = varbinview_arr.nbytes() as u64;
302299

303-
with_counter!(bencher, nbytes)
300+
with_byte_counter(bencher, nbytes)
304301
.with_inputs(|| &varbinview_arr)
305302
.bench_refs(|a| dict_encode(a.as_ref()).unwrap());
306303
}
@@ -311,7 +308,7 @@ fn bench_dict_decompress_string(bencher: Bencher) {
311308
let dict = dict_encode(varbinview_arr.as_ref()).unwrap();
312309
let nbytes = varbinview_arr.into_array().nbytes() as u64;
313310

314-
with_counter!(bencher, nbytes)
311+
with_byte_counter(bencher, nbytes)
315312
.with_inputs(|| &dict)
316313
.bench_refs(|a| a.to_canonical());
317314
}
@@ -322,7 +319,7 @@ fn bench_fsst_compress_string(bencher: Bencher) {
322319
let fsst_compressor = fsst_train_compressor(&varbinview_arr);
323320
let nbytes = varbinview_arr.nbytes() as u64;
324321

325-
with_counter!(bencher, nbytes)
322+
with_byte_counter(bencher, nbytes)
326323
.with_inputs(|| &varbinview_arr)
327324
.bench_refs(|a| fsst_compress(*a, &fsst_compressor));
328325
}
@@ -334,7 +331,7 @@ fn bench_fsst_decompress_string(bencher: Bencher) {
334331
let fsst_array = fsst_compress(&varbinview_arr, &fsst_compressor);
335332
let nbytes = varbinview_arr.into_array().nbytes() as u64;
336333

337-
with_counter!(bencher, nbytes)
334+
with_byte_counter(bencher, nbytes)
338335
.with_inputs(|| &fsst_array)
339336
.bench_refs(|a| a.to_canonical());
340337
}
@@ -346,7 +343,7 @@ fn bench_zstd_compress_string(bencher: Bencher) {
346343
let nbytes = varbinview_arr.nbytes() as u64;
347344
let array = varbinview_arr.into_array();
348345

349-
with_counter!(bencher, nbytes)
346+
with_byte_counter(bencher, nbytes)
350347
.with_inputs(|| array.clone())
351348
.bench_values(|a| ZstdArray::from_array(a, 3, 8192).unwrap());
352349
}
@@ -358,7 +355,7 @@ fn bench_zstd_decompress_string(bencher: Bencher) {
358355
let compressed = ZstdArray::from_array(varbinview_arr.clone().into_array(), 3, 8192).unwrap();
359356
let nbytes = varbinview_arr.into_array().nbytes() as u64;
360357

361-
with_counter!(bencher, nbytes)
358+
with_byte_counter(bencher, nbytes)
362359
.with_inputs(|| &compressed)
363360
.bench_refs(|a| a.to_canonical());
364361
}

0 commit comments

Comments
 (0)