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);