From ab3a2545280472d17d16e9f7e5e634532ee243bc Mon Sep 17 00:00:00 2001 From: Andy Grove Date: Fri, 6 Dec 2024 13:41:32 -0700 Subject: [PATCH 1/3] add cast_decimal bench --- arrow-cast/Cargo.toml | 4 +++ arrow-cast/benches/cast_decimal.rs | 45 ++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 arrow-cast/benches/cast_decimal.rs diff --git a/arrow-cast/Cargo.toml b/arrow-cast/Cargo.toml index 4046f5226094..a62e25eb9a57 100644 --- a/arrow-cast/Cargo.toml +++ b/arrow-cast/Cargo.toml @@ -77,3 +77,7 @@ harness = false [[bench]] name = "parse_decimal" harness = false + +[[bench]] +name = "cast_decimal" +harness = false diff --git a/arrow-cast/benches/cast_decimal.rs b/arrow-cast/benches/cast_decimal.rs new file mode 100644 index 000000000000..a7d035ab26fc --- /dev/null +++ b/arrow-cast/benches/cast_decimal.rs @@ -0,0 +1,45 @@ +// 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}; +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![ + 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); From 2fa5b13941bd8c9f18ffb4ea3d31039080cf0d89 Mon Sep 17 00:00:00 2001 From: Andy Grove Date: Fri, 6 Dec 2024 13:53:57 -0700 Subject: [PATCH 2/3] format --- arrow-cast/benches/cast_decimal.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arrow-cast/benches/cast_decimal.rs b/arrow-cast/benches/cast_decimal.rs index a7d035ab26fc..cc85fc171137 100644 --- a/arrow-cast/benches/cast_decimal.rs +++ b/arrow-cast/benches/cast_decimal.rs @@ -32,7 +32,8 @@ fn criterion_benchmark(c: &mut Criterion) { i128::MAX, i128::MIN, ]) - .with_precision_and_scale(24, 2).unwrap(), + .with_precision_and_scale(24, 2) + .unwrap(), ); let options = CastOptions::default(); let d = black_box(decimals); From 9c9e49967860a04782b2a49b933111bf09e099c3 Mon Sep 17 00:00:00 2001 From: Andy Grove Date: Fri, 6 Dec 2024 17:12:36 -0700 Subject: [PATCH 3/3] address feedback --- arrow-cast/Cargo.toml | 4 --- arrow-cast/benches/cast_decimal.rs | 46 ------------------------------ arrow/benches/cast_kernels.rs | 3 ++ 3 files changed, 3 insertions(+), 50 deletions(-) delete mode 100644 arrow-cast/benches/cast_decimal.rs diff --git a/arrow-cast/Cargo.toml b/arrow-cast/Cargo.toml index a62e25eb9a57..4046f5226094 100644 --- a/arrow-cast/Cargo.toml +++ b/arrow-cast/Cargo.toml @@ -77,7 +77,3 @@ harness = false [[bench]] name = "parse_decimal" harness = false - -[[bench]] -name = "cast_decimal" -harness = false diff --git a/arrow-cast/benches/cast_decimal.rs b/arrow-cast/benches/cast_decimal.rs deleted file mode 100644 index cc85fc171137..000000000000 --- a/arrow-cast/benches/cast_decimal.rs +++ /dev/null @@ -1,46 +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. - -use arrow_array::{ArrayRef, Decimal128Array}; -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![ - 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); diff --git a/arrow/benches/cast_kernels.rs b/arrow/benches/cast_kernels.rs index ec7990d3d764..5c4fcff13dee 100644 --- a/arrow/benches/cast_kernels.rs +++ b/arrow/benches/cast_kernels.rs @@ -250,6 +250,9 @@ fn add_benchmark(c: &mut Criterion) { c.bench_function("cast decimal128 to decimal128 512", |b| { b.iter(|| cast_array(&decimal128_array, DataType::Decimal128(30, 5))) }); + c.bench_function("cast decimal128 to decimal128 512 lower precision", |b| { + b.iter(|| cast_array(&decimal128_array, DataType::Decimal128(6, 5))) + }); c.bench_function("cast decimal128 to decimal256 512", |b| { b.iter(|| cast_array(&decimal128_array, DataType::Decimal256(50, 5))) });