|
| 1 | +// Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +// or more contributor license agreements. See the NOTICE file |
| 3 | +// distributed with this work for additional information |
| 4 | +// regarding copyright ownership. The ASF licenses this file |
| 5 | +// to you under the Apache License, Version 2.0 (the |
| 6 | +// "License"); you may not use this file except in compliance |
| 7 | +// with the License. You may obtain a copy of the License at |
| 8 | +// |
| 9 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +// Unless required by applicable law or agreed to in writing, |
| 12 | +// software distributed under the License is distributed on an |
| 13 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +// KIND, either express or implied. See the License for the |
| 15 | +// specific language governing permissions and limitations |
| 16 | +// under the License. |
| 17 | + |
| 18 | +extern crate criterion; |
| 19 | + |
| 20 | +use arrow::{ |
| 21 | + datatypes::{Int32Type, Int64Type}, |
| 22 | + util::bench_util::create_primitive_array, |
| 23 | +}; |
| 24 | +use criterion::{black_box, criterion_group, criterion_main, Criterion}; |
| 25 | +use datafusion_expr::ColumnarValue; |
| 26 | +use datafusion_functions::string; |
| 27 | +use std::sync::Arc; |
| 28 | + |
| 29 | +fn criterion_benchmark(c: &mut Criterion) { |
| 30 | + let hex = string::to_hex(); |
| 31 | + let size = 1024; |
| 32 | + let i32_array = Arc::new(create_primitive_array::<Int32Type>(size, 0.2)); |
| 33 | + let batch_len = i32_array.len(); |
| 34 | + let i32_args = vec![ColumnarValue::Array(i32_array)]; |
| 35 | + c.bench_function(&format!("to_hex i32 array: {}", size), |b| { |
| 36 | + b.iter(|| black_box(hex.invoke_batch(&i32_args, batch_len).unwrap())) |
| 37 | + }); |
| 38 | + let i64_array = Arc::new(create_primitive_array::<Int64Type>(size, 0.2)); |
| 39 | + let batch_len = i64_array.len(); |
| 40 | + let i64_args = vec![ColumnarValue::Array(i64_array)]; |
| 41 | + c.bench_function(&format!("to_hex i64 array: {}", size), |b| { |
| 42 | + b.iter(|| black_box(hex.invoke_batch(&i64_args, batch_len).unwrap())) |
| 43 | + }); |
| 44 | +} |
| 45 | + |
| 46 | +criterion_group!(benches, criterion_benchmark); |
| 47 | +criterion_main!(benches); |
0 commit comments