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

chore: add cast_decimal benchmark #6850

Merged
merged 3 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 4 additions & 0 deletions arrow-cast/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,7 @@ harness = false
[[bench]]
name = "parse_decimal"
harness = false

[[bench]]
name = "cast_decimal"
harness = false
46 changes: 46 additions & 0 deletions arrow-cast/benches/cast_decimal.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// 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_array::{ArrayRef, Decimal128Array};
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should put this along side the other benchmarks for cast in https://github.com/apache/arrow-rs/blob/main/arrow/benches/cast_kernels.rs#L1-L0

Copy link
Member Author

Choose a reason for hiding this comment

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

and it turns out that we already have tests for this that I can easily modify 🙄

    c.bench_function("cast decimal128 to decimal128 512", |b| {
        b.iter(|| cast_array(&decimal128_array, DataType::Decimal128(30, 5)))
    });

use arrow_cast::{cast_with_options, CastOptions};
use arrow_schema::DataType;
use criterion::*;
use std::sync::Arc;

fn criterion_benchmark(c: &mut Criterion) {
let decimals: ArrayRef = Arc::new(
Decimal128Array::from(vec![
Copy link
Contributor

Choose a reason for hiding this comment

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

I recommend creating a slightly larger array that mirrors actual workloads (e.g. 4k or 8k values, maybe just repeating these values multiple times).

Using a small array like may amplify the overheads of function invocation compared to the actual work being done

0,
1234,
-1234,
1234567,
-1234567,
i128::MAX,
i128::MIN,
])
.with_precision_and_scale(24, 2)
.unwrap(),
);
let options = CastOptions::default();
let d = black_box(decimals);
c.bench_function("cast_decimal", |b| {
b.iter(|| cast_with_options(&d, &DataType::Decimal128(6, 2), &options).unwrap());
});
}

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