From d4b6aaa0985d44b9fc12a12524aa3954a8ce1537 Mon Sep 17 00:00:00 2001 From: "Jorge C. Leitao" Date: Thu, 26 Aug 2021 10:28:57 +0000 Subject: [PATCH] Refactored benches for null_count. --- Cargo.toml | 2 +- benches/count_zeros.rs | 24 ++++++++++++++++++++++++ benches/null_count.rs | 42 ------------------------------------------ benches/unset_count.rs | 24 ++++++++++++++++++++++++ 4 files changed, 49 insertions(+), 43 deletions(-) create mode 100644 benches/count_zeros.rs delete mode 100644 benches/null_count.rs create mode 100644 benches/unset_count.rs diff --git a/Cargo.toml b/Cargo.toml index e057c40de6e..ad96f42e54e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -141,7 +141,7 @@ name = "length_kernel" harness = false [[bench]] -name = "null_count" +name = "count_zeros" harness = false [[bench]] diff --git a/benches/count_zeros.rs b/benches/count_zeros.rs new file mode 100644 index 00000000000..f37d411bdf4 --- /dev/null +++ b/benches/count_zeros.rs @@ -0,0 +1,24 @@ +use arrow2::bitmap::utils::null_count; + +use criterion::{criterion_group, criterion_main, Criterion}; + +fn add_benchmark(c: &mut Criterion) { + (10..=20).step_by(2).for_each(|log2_size| { + let size = 2usize.pow(log2_size); + + let bytes = (0..size as u32) + .map(|x| 0b01011011u8.rotate_left(x)) + .collect::>(); + + c.bench_function(&format!("count_zeros 2^{}", log2_size), |b| { + b.iter(|| null_count(&bytes, 0, bytes.len() * 8)) + }); + + c.bench_function(&format!("count_zeros offset 2^{}", log2_size), |b| { + b.iter(|| null_count(&bytes, 10, bytes.len() * 8 - 10)) + }); + }) +} + +criterion_group!(benches, add_benchmark); +criterion_main!(benches); diff --git a/benches/null_count.rs b/benches/null_count.rs deleted file mode 100644 index 81eb4a8fbc9..00000000000 --- a/benches/null_count.rs +++ /dev/null @@ -1,42 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -extern crate arrow2; - -use arrow2::bitmap::utils::null_count; - -use criterion::{criterion_group, criterion_main, Criterion}; - -fn add_benchmark(c: &mut Criterion) { - let bytes = (0..1026) - .map(|x| 0b01011011u8.rotate_left(x)) - .collect::>(); - - c.bench_function("null_count", |b| { - b.iter(|| null_count(&bytes, 0, bytes.len() * 8)) - }); - - c.bench_function("null_count_offset", |b| { - b.iter(|| null_count(&bytes, 10, bytes.len() * 8 - 10)) - }); - - c.bench_function("null_count_sliced", |b| { - b.iter(|| null_count(&bytes, 10, bytes.len() * 8 - 20)) - }); -} - -criterion_group!(benches, add_benchmark); -criterion_main!(benches); diff --git a/benches/unset_count.rs b/benches/unset_count.rs new file mode 100644 index 00000000000..6bc0e1907b4 --- /dev/null +++ b/benches/unset_count.rs @@ -0,0 +1,24 @@ +use arrow2::bitmap::utils::null_count; + +use criterion::{criterion_group, criterion_main, Criterion}; + +fn add_benchmark(c: &mut Criterion) { + (10..=20).step_by(2).for_each(|log2_size| { + let size = 2usize.pow(log2_size); + + let bytes = (0..size as u32) + .map(|x| 0b01011011u8.rotate_left(x)) + .collect::>(); + + c.bench_function(&format!("unset_count 2^{}", log2_size), |b| { + b.iter(|| null_count(&bytes, 0, bytes.len() * 8)) + }); + + c.bench_function(&format!("unset_count offset 2^{}", log2_size), |b| { + b.iter(|| null_count(&bytes, 10, bytes.len() * 8 - 10)) + }); + }) +} + +criterion_group!(benches, add_benchmark); +criterion_main!(benches);