-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Speedup
date_trunc
(~20% time reduction) (#14593)
* add bench for date_trunc * Optimize date_trunc using try_unary date_trunc_minute_1000 time: [12.745 µs 12.794 µs 12.849 µs] change: [-19.871% -19.544% -19.210%] (p = 0.00 < 0.05) Performance has improved. Found 1 outliers among 100 measurements (1.00%) 1 (1.00%) high mild remove todo --------- Co-authored-by: Simon Vandel Sillesen <svs@svs-MacBook-Pro.local>
- Loading branch information
1 parent
21dcc27
commit abb7669
Showing
3 changed files
with
95 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// 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. | ||
|
||
extern crate criterion; | ||
|
||
use std::sync::Arc; | ||
|
||
use arrow::array::{Array, ArrayRef, TimestampSecondArray}; | ||
use criterion::{black_box, criterion_group, criterion_main, Criterion}; | ||
use datafusion_common::ScalarValue; | ||
use rand::rngs::ThreadRng; | ||
use rand::Rng; | ||
|
||
use datafusion_expr::ColumnarValue; | ||
use datafusion_functions::datetime::date_trunc; | ||
|
||
fn timestamps(rng: &mut ThreadRng) -> TimestampSecondArray { | ||
let mut seconds = vec![]; | ||
for _ in 0..1000 { | ||
seconds.push(rng.gen_range(0..1_000_000)); | ||
} | ||
|
||
TimestampSecondArray::from(seconds) | ||
} | ||
|
||
fn criterion_benchmark(c: &mut Criterion) { | ||
c.bench_function("date_trunc_minute_1000", |b| { | ||
let mut rng = rand::thread_rng(); | ||
let timestamps_array = Arc::new(timestamps(&mut rng)) as ArrayRef; | ||
let batch_len = timestamps_array.len(); | ||
let precision = | ||
ColumnarValue::Scalar(ScalarValue::Utf8(Some("minute".to_string()))); | ||
let timestamps = ColumnarValue::Array(timestamps_array); | ||
let udf = date_trunc(); | ||
|
||
b.iter(|| { | ||
black_box( | ||
udf.invoke_batch(&[precision.clone(), timestamps.clone()], batch_len) | ||
.expect("date_trunc should work on valid values"), | ||
) | ||
}) | ||
}); | ||
} | ||
|
||
criterion_group!(benches, criterion_benchmark); | ||
criterion_main!(benches); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters