Skip to content

Commit 4249e4e

Browse files
authored
bench: add range_and_generate_series (#19428)
## Which issue does this PR close? N/A ## Rationale for this change I want to optimize the range for int64 and I need benches before ## What changes are included in this PR? add benchmark for `range` and `generate_series` for Int64 ## Are these changes tested? N/A ## Are there any user-facing changes? Nope
1 parent d8e68a4 commit 4249e4e

File tree

2 files changed

+94
-0
lines changed

2 files changed

+94
-0
lines changed

datafusion/core/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,10 @@ harness = false
238238
name = "parquet_query_sql"
239239
required-features = ["parquet"]
240240

241+
[[bench]]
242+
harness = false
243+
name = "range_and_generate_series"
244+
241245
[[bench]]
242246
harness = false
243247
name = "sql_planner"
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
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+
#[macro_use]
19+
extern crate criterion;
20+
extern crate datafusion;
21+
22+
mod data_utils;
23+
24+
use crate::criterion::Criterion;
25+
use datafusion::execution::context::SessionContext;
26+
use parking_lot::Mutex;
27+
use std::hint::black_box;
28+
use std::sync::Arc;
29+
use tokio::runtime::Runtime;
30+
31+
#[expect(clippy::needless_pass_by_value)]
32+
fn query(ctx: Arc<Mutex<SessionContext>>, rt: &Runtime, sql: &str) {
33+
let df = rt.block_on(ctx.lock().sql(sql)).unwrap();
34+
black_box(rt.block_on(df.collect()).unwrap());
35+
}
36+
37+
fn create_context() -> Arc<Mutex<SessionContext>> {
38+
let ctx = SessionContext::new();
39+
Arc::new(Mutex::new(ctx))
40+
}
41+
42+
fn criterion_benchmark(c: &mut Criterion) {
43+
let ctx = create_context();
44+
let rt = Runtime::new().unwrap();
45+
46+
c.bench_function("range(1000000)", |b| {
47+
b.iter(|| query(ctx.clone(), &rt, "SELECT value from range(1000000)"))
48+
});
49+
50+
c.bench_function("generate_series(1000000)", |b| {
51+
b.iter(|| {
52+
query(
53+
ctx.clone(),
54+
&rt,
55+
"SELECT value from generate_series(1000000)",
56+
)
57+
})
58+
});
59+
60+
c.bench_function("range(0, 1000000, 5)", |b| {
61+
b.iter(|| query(ctx.clone(), &rt, "SELECT value from range(0, 1000000, 5)"))
62+
});
63+
64+
c.bench_function("generate_series(0, 1000000, 5)", |b| {
65+
b.iter(|| {
66+
query(
67+
ctx.clone(),
68+
&rt,
69+
"SELECT value from generate_series(0, 1000000, 5)",
70+
)
71+
})
72+
});
73+
74+
c.bench_function("range(1000000, 0, -5)", |b| {
75+
b.iter(|| query(ctx.clone(), &rt, "SELECT value from range(1000000, 0, -5)"))
76+
});
77+
78+
c.bench_function("generate_series(1000000, 0, -5)", |b| {
79+
b.iter(|| {
80+
query(
81+
ctx.clone(),
82+
&rt,
83+
"SELECT value from generate_series(1000000, 0, -5)",
84+
)
85+
})
86+
});
87+
}
88+
89+
criterion_group!(benches, criterion_benchmark);
90+
criterion_main!(benches);

0 commit comments

Comments
 (0)