From bba387d6fff2aea0f4d929d428041158c15989bc Mon Sep 17 00:00:00 2001 From: Edd Robinson Date: Wed, 26 May 2021 23:01:15 +0100 Subject: [PATCH] refactor: fix benchmarks --- read_buffer/benches/plain.rs | 55 ++++++++++++++++++++------------ read_buffer/benches/sum_fixed.rs | 53 ++++++++++++++++++------------ read_buffer/src/lib.rs | 5 ++- 3 files changed, 71 insertions(+), 42 deletions(-) diff --git a/read_buffer/benches/plain.rs b/read_buffer/benches/plain.rs index f6c3a03f5a..769949bcda 100644 --- a/read_buffer/benches/plain.rs +++ b/read_buffer/benches/plain.rs @@ -1,11 +1,12 @@ +use rand::prelude::*; use std::mem::size_of; use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput}; -use rand::prelude::*; +use arrow::array::PrimitiveArray; use arrow::datatypes::*; -use read_buffer::benchmarks::Fixed; -use read_buffer::benchmarks::FixedNull; + +use read_buffer::benchmarks::{ByteTrimmer, Fixed, FixedNull, NoOpTranscoder, ScalarEncoding}; const ROWS: [usize; 5] = [10, 100, 1_000, 10_000, 60_000]; const CHUNKS: [Chunks; 4] = [ @@ -84,8 +85,9 @@ fn benchmark_plain_sum( match enc_type { EncType::Fixed => { - let encoding = Fixed::::from( - (0..num_rows as i64).collect::>().as_slice(), + let encoding = Fixed::::new( + (0..num_rows as i64).collect::>(), + NoOpTranscoder {}, ); group.bench_with_input( @@ -97,14 +99,17 @@ fn benchmark_plain_sum( |b, input| { b.iter(|| { // do work - let _ = encoding.sum::(&input); + let _ = encoding.sum(&input); }); }, ); } EncType::Arrow => { - let encoding = FixedNull::::from( - (0..num_rows as i64).collect::>().as_slice(), + let encoding = FixedNull::::new( + PrimitiveArray::from( + (0..num_rows as i64).collect::>(), + ), + NoOpTranscoder {}, ); group.bench_with_input( @@ -116,7 +121,7 @@ fn benchmark_plain_sum( |b, input| { b.iter(|| { // do work - let _ = encoding.sum::(&input); + let _ = encoding.sum(&input); }); }, ); @@ -129,8 +134,9 @@ fn benchmark_plain_sum( match enc_type { EncType::Fixed => { - let encoding = Fixed::::from( - (0..num_rows as i32).collect::>().as_slice(), + let encoding = Fixed::::new( + (0..num_rows as i32).collect::>(), + ByteTrimmer {}, ); group.bench_with_input( @@ -142,14 +148,17 @@ fn benchmark_plain_sum( |b, input| { b.iter(|| { // do work - let _ = encoding.sum::(&input); + let _ = encoding.sum(&input); }); }, ); } EncType::Arrow => { - let encoding = FixedNull::::from( - (0..num_rows as i32).collect::>().as_slice(), + let encoding = FixedNull::::new( + PrimitiveArray::from( + (0..num_rows as i32).collect::>(), + ), + ByteTrimmer {}, ); group.bench_with_input( @@ -161,7 +170,7 @@ fn benchmark_plain_sum( |b, input| { b.iter(|| { // do work - let _ = encoding.sum::(&input); + let _ = encoding.sum(&input); }); }, ); @@ -174,8 +183,9 @@ fn benchmark_plain_sum( match enc_type { EncType::Fixed => { - let encoding = Fixed::::from( - (0..num_rows as i16).collect::>().as_slice(), + let encoding = Fixed::::new( + (0..num_rows as i16).collect::>(), + ByteTrimmer {}, ); group.bench_with_input( @@ -187,14 +197,17 @@ fn benchmark_plain_sum( |b, input| { b.iter(|| { // do work - let _ = encoding.sum::(&input); + let _ = encoding.sum(&input); }); }, ); } EncType::Arrow => { - let encoding = FixedNull::::from( - (0..num_rows as i16).collect::>().as_slice(), + let encoding = FixedNull::::new( + PrimitiveArray::from( + (0..num_rows as i16).collect::>(), + ), + ByteTrimmer {}, ); group.bench_with_input( @@ -206,7 +219,7 @@ fn benchmark_plain_sum( |b, input| { b.iter(|| { // do work - let _ = encoding.sum::(&input); + let _ = encoding.sum(&input); }); }, ); diff --git a/read_buffer/benches/sum_fixed.rs b/read_buffer/benches/sum_fixed.rs index 7c38172b5f..465f1518eb 100644 --- a/read_buffer/benches/sum_fixed.rs +++ b/read_buffer/benches/sum_fixed.rs @@ -1,11 +1,12 @@ use std::mem::size_of; +use arrow::array::PrimitiveArray; use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput}; use rand::prelude::*; use arrow::datatypes::*; -use read_buffer::benchmarks::Fixed; -use read_buffer::benchmarks::FixedNull; + +use read_buffer::benchmarks::{ByteTrimmer, Fixed, FixedNull, NoOpTranscoder, ScalarEncoding}; const ROWS: [usize; 5] = [10, 100, 1_000, 10_000, 60_000]; const CHUNKS: [Chunks; 4] = [ @@ -84,8 +85,9 @@ fn benchmark_none_sum( match enc_type { EncType::Fixed => { - let encoding = Fixed::::from( - (0..num_rows as i64).collect::>().as_slice(), + let encoding = Fixed::::new( + (0..num_rows as i64).collect::>(), + NoOpTranscoder {}, ); group.bench_with_input( @@ -97,14 +99,17 @@ fn benchmark_none_sum( |b, input| { b.iter(|| { // do work - let _ = encoding.sum::(&input); + let _ = encoding.sum(&input); }); }, ); } EncType::FixedNull => { - let encoding = FixedNull::::from( - (0..num_rows as i64).collect::>().as_slice(), + let encoding = FixedNull::::new( + PrimitiveArray::from( + (0..num_rows as i64).collect::>(), + ), + ByteTrimmer {}, ); group.bench_with_input( @@ -116,7 +121,7 @@ fn benchmark_none_sum( |b, input| { b.iter(|| { // do work - let _ = encoding.sum::(&input); + let _ = encoding.sum(&input); }); }, ); @@ -129,8 +134,9 @@ fn benchmark_none_sum( match enc_type { EncType::Fixed => { - let encoding = Fixed::::from( - (0..num_rows as i32).collect::>().as_slice(), + let encoding = Fixed::::new( + (0..num_rows as i32).collect::>(), + ByteTrimmer {}, ); group.bench_with_input( @@ -142,14 +148,17 @@ fn benchmark_none_sum( |b, input| { b.iter(|| { // do work - let _ = encoding.sum::(&input); + let _ = encoding.sum(&input); }); }, ); } EncType::FixedNull => { - let encoding = FixedNull::::from( - (0..num_rows as i32).collect::>().as_slice(), + let encoding = FixedNull::::new( + PrimitiveArray::from( + (0..num_rows as i32).collect::>(), + ), + ByteTrimmer {}, ); group.bench_with_input( @@ -161,7 +170,7 @@ fn benchmark_none_sum( |b, input| { b.iter(|| { // do work - let _ = encoding.sum::(&input); + let _ = encoding.sum(&input); }); }, ); @@ -174,8 +183,9 @@ fn benchmark_none_sum( match enc_type { EncType::Fixed => { - let encoding = Fixed::::from( - (0..num_rows as i16).collect::>().as_slice(), + let encoding = Fixed::::new( + (0..num_rows as i16).collect::>(), + ByteTrimmer {}, ); group.bench_with_input( @@ -187,14 +197,17 @@ fn benchmark_none_sum( |b, input| { b.iter(|| { // do work - let _ = encoding.sum::(&input); + let _ = encoding.sum(&input); }); }, ); } EncType::FixedNull => { - let encoding = FixedNull::::from( - (0..num_rows as i16).collect::>().as_slice(), + let encoding = FixedNull::::new( + PrimitiveArray::from( + (0..num_rows as i16).collect::>(), + ), + ByteTrimmer {}, ); group.bench_with_input( @@ -206,7 +219,7 @@ fn benchmark_none_sum( |b, input| { b.iter(|| { // do work - let _ = encoding.sum::(&input); + let _ = encoding.sum(&input); }); }, ); diff --git a/read_buffer/src/lib.rs b/read_buffer/src/lib.rs index 3f6328f484..48f8474c8f 100644 --- a/read_buffer/src/lib.rs +++ b/read_buffer/src/lib.rs @@ -22,7 +22,10 @@ pub use table::ReadFilterResults; /// It should not be imported into any non-testing or benchmarking crates. pub mod benchmarks { pub use crate::column::{ - cmp::Operator, encoding::scalar::Fixed, encoding::scalar::FixedNull, encoding::string, + cmp::Operator, + encoding::scalar::transcoders::*, + encoding::scalar::{Fixed, FixedNull, ScalarEncoding}, + encoding::string, Column, RowIDs, }; pub use crate::row_group::{ColumnType, RowGroup};