|
| 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::array::{ArrayRef, StringArray}; |
| 21 | +use criterion::{black_box, criterion_group, criterion_main, Criterion}; |
| 22 | +use datafusion_common::ScalarValue; |
| 23 | +use datafusion_expr::ColumnarValue; |
| 24 | +use datafusion_functions::string; |
| 25 | +use std::sync::Arc; |
| 26 | + |
| 27 | +fn create_args(size: usize, characters: &str) -> Vec<ColumnarValue> { |
| 28 | + let iter = |
| 29 | + std::iter::repeat(format!("{}datafusion{}", characters, characters)).take(size); |
| 30 | + let array = Arc::new(StringArray::from_iter_values(iter)) as ArrayRef; |
| 31 | + vec![ |
| 32 | + ColumnarValue::Array(array), |
| 33 | + ColumnarValue::Scalar(ScalarValue::Utf8(Some(characters.to_string()))), |
| 34 | + ] |
| 35 | +} |
| 36 | + |
| 37 | +fn criterion_benchmark(c: &mut Criterion) { |
| 38 | + let ltrim = string::ltrim(); |
| 39 | + for char in ["\"", "Header:"] { |
| 40 | + for size in [1024, 4096, 8192] { |
| 41 | + let args = create_args(size, char); |
| 42 | + c.bench_function(&format!("ltrim {}: {}", char, size), |b| { |
| 43 | + b.iter(|| black_box(ltrim.invoke(&args))) |
| 44 | + }); |
| 45 | + } |
| 46 | + } |
| 47 | +} |
| 48 | + |
| 49 | +criterion_group!(benches, criterion_benchmark); |
| 50 | +criterion_main!(benches); |
0 commit comments