2022-01-21 23:32:09 +03:00
|
|
|
// Copyright (C) 2019-2022 Aleo Systems Inc.
|
2020-08-18 13:50:26 +03:00
|
|
|
// This file is part of the Leo library.
|
|
|
|
|
|
|
|
// The Leo library is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
|
|
|
// The Leo library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
2022-01-21 23:32:09 +03:00
|
|
|
use leo_ast::Ast;
|
|
|
|
use leo_errors::emitter::Handler;
|
|
|
|
use leo_span::symbol::create_session_if_not_set_then;
|
|
|
|
|
2020-10-07 14:38:11 +03:00
|
|
|
use criterion::{criterion_group, criterion_main, Criterion};
|
2021-03-03 20:59:24 +03:00
|
|
|
use std::time::Duration;
|
2020-08-03 06:33:05 +03:00
|
|
|
|
2022-01-21 23:32:09 +03:00
|
|
|
fn parse_ast(path: &str, input: &str) -> Ast {
|
|
|
|
create_session_if_not_set_then(|_| {
|
|
|
|
leo_parser::parse_ast(&Handler::default(), path, input).expect("failed to parse benchmark")
|
|
|
|
})
|
|
|
|
}
|
2020-08-03 06:33:05 +03:00
|
|
|
|
2022-01-21 23:32:09 +03:00
|
|
|
fn bench_big_if_else(c: &mut Criterion) {
|
|
|
|
let ast = parse_ast("./big_if_else.leo", include_str!("./big_if_else.leo"));
|
2021-03-03 20:59:24 +03:00
|
|
|
c.bench_function("Ast::big_if_else", |b| b.iter(|| &ast));
|
2020-08-03 06:33:05 +03:00
|
|
|
}
|
|
|
|
|
2020-10-07 14:38:11 +03:00
|
|
|
fn bench_big_ternary(c: &mut Criterion) {
|
2022-01-21 23:32:09 +03:00
|
|
|
let ast = parse_ast("./big_ternary.leo", include_str!("./big_ternary.leo"));
|
2021-03-03 20:59:24 +03:00
|
|
|
c.bench_function("Ast::big_ternary", |b| b.iter(|| &ast));
|
2020-10-07 14:38:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
fn bench_big_circuit(c: &mut Criterion) {
|
2022-01-21 23:32:09 +03:00
|
|
|
let ast = parse_ast("./big_circuit.leo", include_str!("./big_circuit.leo"));
|
2021-03-03 20:59:24 +03:00
|
|
|
c.bench_function("Ast::big_circuit", |b| b.iter(|| &ast));
|
2020-10-07 14:38:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
fn bench_long_expr(c: &mut Criterion) {
|
2022-01-21 23:32:09 +03:00
|
|
|
let ast = parse_ast("./long_expr.leo", include_str!("./long_expr.leo"));
|
2021-03-03 20:59:24 +03:00
|
|
|
c.bench_function("Ast::long_expr", |b| b.iter(|| &ast));
|
2020-10-07 14:38:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
fn bench_long_array(c: &mut Criterion) {
|
2022-01-21 23:32:09 +03:00
|
|
|
let ast = parse_ast("./long_array.leo", include_str!("./long_array.leo"));
|
2021-03-03 20:59:24 +03:00
|
|
|
c.bench_function("Ast::long_array", |b| b.iter(|| &ast));
|
2020-10-07 14:38:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
fn bench_many_foos(c: &mut Criterion) {
|
2022-01-21 23:32:09 +03:00
|
|
|
let ast = parse_ast("./many_foos.leo", include_str!("./many_foos.leo"));
|
2021-03-03 20:59:24 +03:00
|
|
|
c.bench_function("Ast::many_foos", |b| b.iter(|| &ast));
|
2020-10-07 14:38:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
fn bench_many_assigns(c: &mut Criterion) {
|
2022-01-21 23:32:09 +03:00
|
|
|
let ast = parse_ast("./many_assigns.leo", include_str!("./many_assigns.leo"));
|
2021-03-03 20:59:24 +03:00
|
|
|
c.bench_function("Ast::many_assigns", |b| b.iter(|| &ast));
|
2020-10-07 14:38:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
criterion_group!(
|
|
|
|
name = benches;
|
|
|
|
config = Criterion::default().sample_size(200).measurement_time(Duration::from_secs(10)).nresamples(200_000);
|
|
|
|
targets = bench_big_circuit,
|
|
|
|
bench_long_expr,
|
|
|
|
bench_big_if_else,
|
|
|
|
bench_big_ternary,
|
|
|
|
bench_long_array,
|
|
|
|
bench_many_assigns,
|
|
|
|
bench_many_foos,
|
|
|
|
);
|
2020-08-03 06:33:05 +03:00
|
|
|
criterion_main!(benches);
|