refactor: fix benchmarks

pull/24376/head
Edd Robinson 2021-05-26 23:01:15 +01:00
parent 7ab27c4468
commit bba387d6ff
3 changed files with 71 additions and 42 deletions

View File

@ -1,11 +1,12 @@
use rand::prelude::*;
use std::mem::size_of; use std::mem::size_of;
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput}; use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput};
use rand::prelude::*;
use arrow::array::PrimitiveArray;
use arrow::datatypes::*; 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 ROWS: [usize; 5] = [10, 100, 1_000, 10_000, 60_000];
const CHUNKS: [Chunks; 4] = [ const CHUNKS: [Chunks; 4] = [
@ -84,8 +85,9 @@ fn benchmark_plain_sum(
match enc_type { match enc_type {
EncType::Fixed => { EncType::Fixed => {
let encoding = Fixed::<i64>::from( let encoding = Fixed::<i64, i64, _>::new(
(0..num_rows as i64).collect::<Vec<i64>>().as_slice(), (0..num_rows as i64).collect::<Vec<i64>>(),
NoOpTranscoder {},
); );
group.bench_with_input( group.bench_with_input(
@ -97,14 +99,17 @@ fn benchmark_plain_sum(
|b, input| { |b, input| {
b.iter(|| { b.iter(|| {
// do work // do work
let _ = encoding.sum::<i64>(&input); let _ = encoding.sum(&input);
}); });
}, },
); );
} }
EncType::Arrow => { EncType::Arrow => {
let encoding = FixedNull::<Int64Type>::from( let encoding = FixedNull::<Int64Type, i64, _>::new(
(0..num_rows as i64).collect::<Vec<i64>>().as_slice(), PrimitiveArray::from(
(0..num_rows as i64).collect::<Vec<i64>>(),
),
NoOpTranscoder {},
); );
group.bench_with_input( group.bench_with_input(
@ -116,7 +121,7 @@ fn benchmark_plain_sum(
|b, input| { |b, input| {
b.iter(|| { b.iter(|| {
// do work // do work
let _ = encoding.sum::<i64>(&input); let _ = encoding.sum(&input);
}); });
}, },
); );
@ -129,8 +134,9 @@ fn benchmark_plain_sum(
match enc_type { match enc_type {
EncType::Fixed => { EncType::Fixed => {
let encoding = Fixed::<i32>::from( let encoding = Fixed::<i32, i64, _>::new(
(0..num_rows as i32).collect::<Vec<i32>>().as_slice(), (0..num_rows as i32).collect::<Vec<i32>>(),
ByteTrimmer {},
); );
group.bench_with_input( group.bench_with_input(
@ -142,14 +148,17 @@ fn benchmark_plain_sum(
|b, input| { |b, input| {
b.iter(|| { b.iter(|| {
// do work // do work
let _ = encoding.sum::<i64>(&input); let _ = encoding.sum(&input);
}); });
}, },
); );
} }
EncType::Arrow => { EncType::Arrow => {
let encoding = FixedNull::<Int32Type>::from( let encoding = FixedNull::<Int32Type, i64, _>::new(
(0..num_rows as i32).collect::<Vec<i32>>().as_slice(), PrimitiveArray::from(
(0..num_rows as i32).collect::<Vec<i32>>(),
),
ByteTrimmer {},
); );
group.bench_with_input( group.bench_with_input(
@ -161,7 +170,7 @@ fn benchmark_plain_sum(
|b, input| { |b, input| {
b.iter(|| { b.iter(|| {
// do work // do work
let _ = encoding.sum::<i64>(&input); let _ = encoding.sum(&input);
}); });
}, },
); );
@ -174,8 +183,9 @@ fn benchmark_plain_sum(
match enc_type { match enc_type {
EncType::Fixed => { EncType::Fixed => {
let encoding = Fixed::<i16>::from( let encoding = Fixed::<i16, i64, _>::new(
(0..num_rows as i16).collect::<Vec<i16>>().as_slice(), (0..num_rows as i16).collect::<Vec<i16>>(),
ByteTrimmer {},
); );
group.bench_with_input( group.bench_with_input(
@ -187,14 +197,17 @@ fn benchmark_plain_sum(
|b, input| { |b, input| {
b.iter(|| { b.iter(|| {
// do work // do work
let _ = encoding.sum::<i16>(&input); let _ = encoding.sum(&input);
}); });
}, },
); );
} }
EncType::Arrow => { EncType::Arrow => {
let encoding = FixedNull::<Int16Type>::from( let encoding = FixedNull::<Int16Type, i64, _>::new(
(0..num_rows as i16).collect::<Vec<i16>>().as_slice(), PrimitiveArray::from(
(0..num_rows as i16).collect::<Vec<i16>>(),
),
ByteTrimmer {},
); );
group.bench_with_input( group.bench_with_input(
@ -206,7 +219,7 @@ fn benchmark_plain_sum(
|b, input| { |b, input| {
b.iter(|| { b.iter(|| {
// do work // do work
let _ = encoding.sum::<i64>(&input); let _ = encoding.sum(&input);
}); });
}, },
); );

View File

@ -1,11 +1,12 @@
use std::mem::size_of; use std::mem::size_of;
use arrow::array::PrimitiveArray;
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput}; use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput};
use rand::prelude::*; use rand::prelude::*;
use arrow::datatypes::*; 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 ROWS: [usize; 5] = [10, 100, 1_000, 10_000, 60_000];
const CHUNKS: [Chunks; 4] = [ const CHUNKS: [Chunks; 4] = [
@ -84,8 +85,9 @@ fn benchmark_none_sum(
match enc_type { match enc_type {
EncType::Fixed => { EncType::Fixed => {
let encoding = Fixed::<i64>::from( let encoding = Fixed::<i64, i64, _>::new(
(0..num_rows as i64).collect::<Vec<i64>>().as_slice(), (0..num_rows as i64).collect::<Vec<i64>>(),
NoOpTranscoder {},
); );
group.bench_with_input( group.bench_with_input(
@ -97,14 +99,17 @@ fn benchmark_none_sum(
|b, input| { |b, input| {
b.iter(|| { b.iter(|| {
// do work // do work
let _ = encoding.sum::<i64>(&input); let _ = encoding.sum(&input);
}); });
}, },
); );
} }
EncType::FixedNull => { EncType::FixedNull => {
let encoding = FixedNull::<Int64Type>::from( let encoding = FixedNull::<Int64Type, i64, _>::new(
(0..num_rows as i64).collect::<Vec<i64>>().as_slice(), PrimitiveArray::from(
(0..num_rows as i64).collect::<Vec<i64>>(),
),
ByteTrimmer {},
); );
group.bench_with_input( group.bench_with_input(
@ -116,7 +121,7 @@ fn benchmark_none_sum(
|b, input| { |b, input| {
b.iter(|| { b.iter(|| {
// do work // do work
let _ = encoding.sum::<i64>(&input); let _ = encoding.sum(&input);
}); });
}, },
); );
@ -129,8 +134,9 @@ fn benchmark_none_sum(
match enc_type { match enc_type {
EncType::Fixed => { EncType::Fixed => {
let encoding = Fixed::<i32>::from( let encoding = Fixed::<i32, i64, _>::new(
(0..num_rows as i32).collect::<Vec<i32>>().as_slice(), (0..num_rows as i32).collect::<Vec<i32>>(),
ByteTrimmer {},
); );
group.bench_with_input( group.bench_with_input(
@ -142,14 +148,17 @@ fn benchmark_none_sum(
|b, input| { |b, input| {
b.iter(|| { b.iter(|| {
// do work // do work
let _ = encoding.sum::<i64>(&input); let _ = encoding.sum(&input);
}); });
}, },
); );
} }
EncType::FixedNull => { EncType::FixedNull => {
let encoding = FixedNull::<Int32Type>::from( let encoding = FixedNull::<Int32Type, i64, _>::new(
(0..num_rows as i32).collect::<Vec<i32>>().as_slice(), PrimitiveArray::from(
(0..num_rows as i32).collect::<Vec<i32>>(),
),
ByteTrimmer {},
); );
group.bench_with_input( group.bench_with_input(
@ -161,7 +170,7 @@ fn benchmark_none_sum(
|b, input| { |b, input| {
b.iter(|| { b.iter(|| {
// do work // do work
let _ = encoding.sum::<i64>(&input); let _ = encoding.sum(&input);
}); });
}, },
); );
@ -174,8 +183,9 @@ fn benchmark_none_sum(
match enc_type { match enc_type {
EncType::Fixed => { EncType::Fixed => {
let encoding = Fixed::<i16>::from( let encoding = Fixed::<i16, i64, _>::new(
(0..num_rows as i16).collect::<Vec<i16>>().as_slice(), (0..num_rows as i16).collect::<Vec<i16>>(),
ByteTrimmer {},
); );
group.bench_with_input( group.bench_with_input(
@ -187,14 +197,17 @@ fn benchmark_none_sum(
|b, input| { |b, input| {
b.iter(|| { b.iter(|| {
// do work // do work
let _ = encoding.sum::<i64>(&input); let _ = encoding.sum(&input);
}); });
}, },
); );
} }
EncType::FixedNull => { EncType::FixedNull => {
let encoding = FixedNull::<Int16Type>::from( let encoding = FixedNull::<Int16Type, i64, _>::new(
(0..num_rows as i16).collect::<Vec<i16>>().as_slice(), PrimitiveArray::from(
(0..num_rows as i16).collect::<Vec<i16>>(),
),
ByteTrimmer {},
); );
group.bench_with_input( group.bench_with_input(
@ -206,7 +219,7 @@ fn benchmark_none_sum(
|b, input| { |b, input| {
b.iter(|| { b.iter(|| {
// do work // do work
let _ = encoding.sum::<i64>(&input); let _ = encoding.sum(&input);
}); });
}, },
); );

View File

@ -22,7 +22,10 @@ pub use table::ReadFilterResults;
/// It should not be imported into any non-testing or benchmarking crates. /// It should not be imported into any non-testing or benchmarking crates.
pub mod benchmarks { pub mod benchmarks {
pub use crate::column::{ 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, Column, RowIDs,
}; };
pub use crate::row_group::{ColumnType, RowGroup}; pub use crate::row_group::{ColumnType, RowGroup};