Skip to content

Commit 365900f

Browse files
committed
chore(query): add numeric if evaluator benchmarks
Extracted from commit 87eb181 so the pre-optimization baseline can be benchmarked directly.
1 parent ca7d1d9 commit 365900f

1 file changed

Lines changed: 53 additions & 0 deletions

File tree

src/query/functions/benches/bench.rs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,59 @@ fn main() {
1616
divan::main();
1717
}
1818

19+
#[divan::bench_group(sample_count = 30)]
20+
mod numeric_if {
21+
use databend_common_expression::BlockEntry;
22+
use databend_common_expression::DataBlock;
23+
use databend_common_expression::Evaluator;
24+
use databend_common_expression::FromData;
25+
use databend_common_expression::FunctionContext;
26+
use databend_common_expression::type_check;
27+
use databend_common_expression::types::DataType;
28+
use databend_common_expression::types::NumberDataType;
29+
use databend_common_expression::types::number::Int64Type;
30+
use databend_common_expression_test_support as parser;
31+
use databend_common_functions::BUILTIN_FUNCTIONS;
32+
use divan::counter::ItemsCount;
33+
34+
fn bench_expr(bencher: divan::Bencher, sql: &str, rows: usize) {
35+
let raw_expr = parser::parse_raw_expr(
36+
sql,
37+
&[("x", DataType::Number(NumberDataType::Int64))],
38+
&BUILTIN_FUNCTIONS,
39+
);
40+
let expr = type_check::check(&raw_expr, &BUILTIN_FUNCTIONS).unwrap();
41+
let values = (0..rows).map(|value| value as i64).collect::<Vec<_>>();
42+
let block = DataBlock::new(vec![BlockEntry::Column(Int64Type::from_data(values))], rows);
43+
let func_ctx = FunctionContext::default();
44+
let evaluator = Evaluator::new(&block, &func_ctx, &BUILTIN_FUNCTIONS);
45+
46+
bencher
47+
.counter(ItemsCount::new(rows))
48+
.bench(|| evaluator.run(&expr).unwrap());
49+
}
50+
51+
// 65,536 is the default max_block_size; 1,048,576 is a stress size.
52+
#[divan::bench(args = [65_536, 1_048_576])]
53+
fn if_contains(bencher: divan::Bencher, rows: usize) {
54+
bench_expr(
55+
bencher,
56+
"if(contains([1, 3, 5, 7, 11, 13, 17, 19], x), 0, x % 1000003)",
57+
rows,
58+
);
59+
}
60+
61+
#[divan::bench(args = [65_536, 1_048_576])]
62+
fn if_modulo(bencher: divan::Bencher, rows: usize) {
63+
bench_expr(bencher, "if(x % 1000003 = 0, 0, x % 1000003)", rows);
64+
}
65+
66+
#[divan::bench(args = [65_536, 1_048_576])]
67+
fn if_boolean(bencher: divan::Bencher, rows: usize) {
68+
bench_expr(bencher, "if(x % 2 = 0, x > 10, x < 10)", rows);
69+
}
70+
}
71+
1972
// bench fastest │ slowest │ median │ mean │ samples │ iters
2073
// ╰─ dummy │ │ │ │ │
2174
// ├─ check │ │ │ │ │

0 commit comments

Comments
 (0)