Skip to content

Commit

Permalink
add cast_decimal bench
Browse files Browse the repository at this point in the history
  • Loading branch information
andygrove committed Dec 6, 2024
1 parent 63ad87a commit ab3a254
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
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
45 changes: 45 additions & 0 deletions arrow-cast/benches/cast_decimal.rs
Original file line number Diff line number Diff line change
@@ -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);

0 comments on commit ab3a254

Please sign in to comment.