Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Benchmark for bit_mask (set_bits) #6353

Merged
merged 2 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion arrow-buffer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,14 @@ rand = { version = "0.8", default-features = false, features = ["std", "std_rng"

[build-dependencies]

[[bench]]
name = "bit_mask"
harness = false

[[bench]]
name = "i256"
harness = false

[[bench]]
name = "offset"
harness = false
harness = false
58 changes: 58 additions & 0 deletions arrow-buffer/benches/bit_mask.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// 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.

use arrow_buffer::bit_mask::set_bits;
use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion};

fn criterion_benchmark(c: &mut Criterion) {
let mut group = c.benchmark_group("bit_mask");

for offset_write in [0, 5] {
for offset_read in [0, 5] {
for len in [1, 17, 65] {
for datum in [0u8, 0xADu8] {
let x = (offset_write, offset_read, len, datum);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally found the masking / packing of these fields into x a little hard to read (as I had to maintain a mental mapping that x.2 meant len)

I would have personally found it easier to understand if they were named fields of a struct or maybe just passed by copy.

group.bench_with_input(
BenchmarkId::new(
"set_bits",
format!(
"offset_write_{}_offset_read_{}_len_{}_datum_{}",
x.0, x.1, x.2, x.3
),
),
&x,
|b, &x| {
b.iter(|| {
set_bits(
black_box(&mut [0u8; 9]),
black_box(&[x.3; 9]),
black_box(x.0),
black_box(x.1),
black_box(x.2),
)
});
},
);
}
}
}
}
group.finish();
}

criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);
Loading