|
| 1 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 2 | +// you may not use this file except in compliance with the License. |
| 3 | +// You may obtain a copy of the License at |
| 4 | +// |
| 5 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | +// |
| 7 | +// Unless required by applicable law or agreed to in writing, software |
| 8 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 9 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 10 | +// See the License for the specific language governing permissions and |
| 11 | +// limitations under the License. |
| 12 | + |
| 13 | +use criterion::{criterion_group, criterion_main, Criterion}; |
| 14 | +use sqlparser::dialect::GenericDialect; |
| 15 | +use sqlparser::parser::Parser; |
| 16 | + |
| 17 | +fn basic_queries(c: &mut Criterion) { |
| 18 | + let mut group = c.benchmark_group("sqlparser-rs parsing benchmark"); |
| 19 | + let dialect = GenericDialect {}; |
| 20 | + |
| 21 | + let string = "SELECT * FROM table WHERE 1 = 1"; |
| 22 | + group.bench_function("sqlparser::select", |b| { |
| 23 | + b.iter(|| Parser::parse_sql(&dialect, string)); |
| 24 | + }); |
| 25 | + |
| 26 | + let with_query = " |
| 27 | + WITH derived AS ( |
| 28 | + SELECT MAX(a) AS max_a, |
| 29 | + COUNT(b) AS b_num, |
| 30 | + user_id |
| 31 | + FROM TABLE |
| 32 | + GROUP BY user_id |
| 33 | + ) |
| 34 | + SELECT * FROM table |
| 35 | + LEFT JOIN derived USING (user_id) |
| 36 | + "; |
| 37 | + group.bench_function("sqlparser::with_select", |b| { |
| 38 | + b.iter(|| Parser::parse_sql(&dialect, with_query)); |
| 39 | + }); |
| 40 | +} |
| 41 | + |
| 42 | +criterion_group!(benches, basic_queries); |
| 43 | +criterion_main!(benches); |
0 commit comments