|
| 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::datatypes::{DataType, Field}; |
| 21 | +use arrow::util::bench_util::create_string_array_with_len; |
| 22 | +use criterion::{Criterion, criterion_group, criterion_main}; |
| 23 | +use datafusion_common::config::ConfigOptions; |
| 24 | +use datafusion_expr::ScalarFunctionArgs; |
| 25 | +use datafusion_expr_common::columnar_value::ColumnarValue; |
| 26 | +use datafusion_functions::crypto; |
| 27 | +use std::hint::black_box; |
| 28 | +use std::sync::Arc; |
| 29 | + |
| 30 | +fn criterion_benchmark(c: &mut Criterion) { |
| 31 | + let crypto = vec![ |
| 32 | + crypto::md5(), |
| 33 | + crypto::sha224(), |
| 34 | + crypto::sha256(), |
| 35 | + crypto::sha384(), |
| 36 | + crypto::sha512(), |
| 37 | + ]; |
| 38 | + let config_options = Arc::new(ConfigOptions::default()); |
| 39 | + |
| 40 | + for func in crypto { |
| 41 | + let size = 1024; |
| 42 | + let arr_args = vec![ColumnarValue::Array(Arc::new( |
| 43 | + create_string_array_with_len::<i32>(size, 0.2, 32), |
| 44 | + ))]; |
| 45 | + c.bench_function(&format!("{}_array", func.name()), |b| { |
| 46 | + b.iter(|| { |
| 47 | + let args_cloned = arr_args.clone(); |
| 48 | + black_box(func.invoke_with_args(ScalarFunctionArgs { |
| 49 | + args: args_cloned, |
| 50 | + arg_fields: vec![Field::new("a", DataType::Utf8, true).into()], |
| 51 | + number_rows: size, |
| 52 | + return_field: Field::new("f", DataType::Utf8, true).into(), |
| 53 | + config_options: Arc::clone(&config_options), |
| 54 | + })) |
| 55 | + }) |
| 56 | + }); |
| 57 | + |
| 58 | + let scalar_args = vec![ColumnarValue::Scalar("test_string".into())]; |
| 59 | + c.bench_function(&format!("{}_scalar", func.name()), |b| { |
| 60 | + b.iter(|| { |
| 61 | + let args_cloned = scalar_args.clone(); |
| 62 | + black_box(func.invoke_with_args(ScalarFunctionArgs { |
| 63 | + args: args_cloned, |
| 64 | + arg_fields: vec![Field::new("a", DataType::Utf8, true).into()], |
| 65 | + number_rows: 1, |
| 66 | + return_field: Field::new("f", DataType::Utf8, true).into(), |
| 67 | + config_options: Arc::clone(&config_options), |
| 68 | + })) |
| 69 | + }) |
| 70 | + }); |
| 71 | + } |
| 72 | +} |
| 73 | + |
| 74 | +criterion_group!(benches, criterion_benchmark); |
| 75 | +criterion_main!(benches); |
0 commit comments