Skip to content

Commit

Permalink
Fixed bench
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgecarleitao committed Jan 17, 2021
1 parent 2dca3c8 commit 16bc720
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions rust/arrow/benches/length_kernel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,23 @@ extern crate arrow;
use arrow::array::*;
use arrow::compute::kernels::length::length;

fn bench_length() {
fn bench_length(array: &StringArray) {
criterion::black_box(length(array).unwrap());
}

fn add_benchmark(c: &mut Criterion) {
fn double_vec<T: Clone>(v: Vec<T>) -> Vec<T> {
[&v[..], &v[..]].concat()
}

// double ["hello", " ", "world", "!"] 10 times
let mut values = vec!["one", "on", "o", ""];
let mut expected = vec![3, 2, 1, 0];
for _ in 0..10 {
values = double_vec(values);
expected = double_vec(expected);
}
let array = StringArray::from(values);

criterion::black_box(length(&array).unwrap());
}

fn add_benchmark(c: &mut Criterion) {
c.bench_function("length", |b| b.iter(bench_length));
c.bench_function("length", |b| b.iter(|| bench_length(&array)));
}

criterion_group!(benches, add_benchmark);
Expand Down

0 comments on commit 16bc720

Please sign in to comment.