mirror of
https://github.com/fluencelabs/aquavm
synced 2025-04-25 07:12:16 +00:00
Parser benchmarks (#16)
This commit is contained in:
parent
e4fd7a505c
commit
19ff54e66e
7
Cargo.lock
generated
7
Cargo.lock
generated
@ -15,6 +15,7 @@ version = "0.1.0"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"codespan",
|
"codespan",
|
||||||
"codespan-reporting",
|
"codespan-reporting",
|
||||||
|
"criterion",
|
||||||
"fstrings",
|
"fstrings",
|
||||||
"lalrpop",
|
"lalrpop",
|
||||||
"lalrpop-util",
|
"lalrpop-util",
|
||||||
@ -991,8 +992,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "lalrpop"
|
name = "lalrpop"
|
||||||
version = "0.19.1"
|
version = "0.19.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "git+https://github.com/fluencelabs/lalrpop#149e77b301828392b09da5c2ba634fd19ce3a3a7"
|
||||||
checksum = "60fb56191fb8ed5311597e5750debe6779c9fdb487dbaa5ff302592897d7a2c8"
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ascii-canvas",
|
"ascii-canvas",
|
||||||
"atty",
|
"atty",
|
||||||
@ -1016,8 +1016,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "lalrpop-util"
|
name = "lalrpop-util"
|
||||||
version = "0.19.1"
|
version = "0.19.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "git+https://github.com/fluencelabs/lalrpop#149e77b301828392b09da5c2ba634fd19ce3a3a7"
|
||||||
checksum = "6771161eff561647fad8bb7e745e002c304864fb8f436b52b30acda51fca4408"
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"regex",
|
"regex",
|
||||||
]
|
]
|
||||||
|
@ -5,13 +5,18 @@ authors = ["Fluence Labs"]
|
|||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
lalrpop = { version = "0.19.1", features = ["lexer"] }
|
lalrpop = { git = "https://github.com/fluencelabs/lalrpop", version = "0.19.1", features = ["lexer"] }
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
lalrpop-util = { version = "0.19.1", features = ["lexer"] }
|
lalrpop-util = { git = "https://github.com/fluencelabs/lalrpop", version = "0.19.1", features = ["lexer"] }
|
||||||
regex = "1.4.1"
|
regex = "1.4.1"
|
||||||
codespan = "0.9.5"
|
codespan = "0.9.5"
|
||||||
codespan-reporting = "0.9.5"
|
codespan-reporting = "0.9.5"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
fstrings = "0.2.3"
|
fstrings = "0.2.3"
|
||||||
|
criterion = "0.3.3"
|
||||||
|
|
||||||
|
[[bench]]
|
||||||
|
name = "parser"
|
||||||
|
harness = false
|
||||||
|
130
crates/air-parser/benches/parser.rs
Normal file
130
crates/air-parser/benches/parser.rs
Normal file
@ -0,0 +1,130 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2020 Fluence Labs Limited
|
||||||
|
*
|
||||||
|
* Licensed 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#[macro_use]
|
||||||
|
extern crate fstrings;
|
||||||
|
|
||||||
|
use std::rc::Rc;
|
||||||
|
|
||||||
|
use criterion::criterion_group;
|
||||||
|
use criterion::criterion_main;
|
||||||
|
use criterion::Criterion;
|
||||||
|
|
||||||
|
use air_parser::InstrParser;
|
||||||
|
|
||||||
|
const SOURCE_CODE_BAD: &'static str = r#"(seq
|
||||||
|
(seq
|
||||||
|
(call node ("identity" "") [] void[])
|
||||||
|
(call provider (service_id "{fname}") {arg_list} result)
|
||||||
|
)
|
||||||
|
(seq
|
||||||
|
(call node ("identity" "") [] void[])
|
||||||
|
(call "{LOCAL_VM}" ("return" "result") [result] void[])
|
||||||
|
)
|
||||||
|
)"#;
|
||||||
|
|
||||||
|
const SOURCE_CODE_GOOD: &'static str = r#"
|
||||||
|
(seq
|
||||||
|
(seq
|
||||||
|
(call node ("identity" "") [] void[])
|
||||||
|
(call provider (service_id "fname") [arg list] result)
|
||||||
|
)
|
||||||
|
(seq
|
||||||
|
(call node ("identity" "") [] void[])
|
||||||
|
(call "local_vm" ("return" "result") [result] void[])
|
||||||
|
)
|
||||||
|
)"#;
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod gen {
|
||||||
|
use crate::SOURCE_CODE_GOOD;
|
||||||
|
|
||||||
|
pub fn seq(left: &str, right: &str) -> String {
|
||||||
|
f!(r"(seq {left} {right})")
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn deep_seq(mut depth: usize) -> String {
|
||||||
|
let mut instr = SOURCE_CODE_GOOD.to_string();
|
||||||
|
loop {
|
||||||
|
depth -= 1;
|
||||||
|
if depth == 0 {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
instr = seq(&instr, &instr)
|
||||||
|
}
|
||||||
|
|
||||||
|
instr
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn bench_creation(c: &mut Criterion) {
|
||||||
|
c.bench_function("create_parser", move |b| b.iter(move || InstrParser::new()));
|
||||||
|
}
|
||||||
|
|
||||||
|
fn parse(c: &mut Criterion) {
|
||||||
|
let parser = Rc::new(InstrParser::new());
|
||||||
|
c.bench_function(
|
||||||
|
format!("parse {} bytes", SOURCE_CODE_GOOD.len()).as_str(),
|
||||||
|
move |b| {
|
||||||
|
let parser = parser.clone();
|
||||||
|
b.iter(move || {
|
||||||
|
parser
|
||||||
|
.clone()
|
||||||
|
.parse(&mut Vec::new(), SOURCE_CODE_GOOD)
|
||||||
|
.expect("success")
|
||||||
|
})
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn parse_to_fail(c: &mut Criterion) {
|
||||||
|
let parser = Rc::new(InstrParser::new());
|
||||||
|
c.bench_function(
|
||||||
|
format!("parse {} bytes to FAIL", SOURCE_CODE_BAD.len()).as_str(),
|
||||||
|
move |b| {
|
||||||
|
let parser = parser.clone();
|
||||||
|
b.iter(move || parser.clone().parse(&mut Vec::new(), SOURCE_CODE_BAD))
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn parse_deep(c: &mut Criterion) {
|
||||||
|
let parser = Rc::new(InstrParser::new());
|
||||||
|
let source_code: Vec<_> = (1..10).map(gen::deep_seq).collect();
|
||||||
|
let index: Vec<_> = source_code
|
||||||
|
.iter()
|
||||||
|
.enumerate()
|
||||||
|
.map(|(i, code)| (i, code.len()))
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
c.bench_function_over_inputs(
|
||||||
|
"parse generated script",
|
||||||
|
move |b, (i, _)| {
|
||||||
|
let parser = parser.clone();
|
||||||
|
let code = &source_code[*i];
|
||||||
|
b.iter(move || {
|
||||||
|
parser
|
||||||
|
.clone()
|
||||||
|
.parse(&mut Vec::new(), code)
|
||||||
|
.expect("success")
|
||||||
|
});
|
||||||
|
},
|
||||||
|
index,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
criterion_group!(benches, bench_creation, parse, parse_to_fail, parse_deep);
|
||||||
|
criterion_main!(benches);
|
@ -23,7 +23,7 @@ use Value::*;
|
|||||||
use fstrings::f;
|
use fstrings::f;
|
||||||
|
|
||||||
fn parse(source_code: &str) -> Instruction {
|
fn parse(source_code: &str) -> Instruction {
|
||||||
*super::parse(source_code).expect("parsing failed")
|
*crate::parse(source_code).expect("parsing failed")
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -4,17 +4,18 @@
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate fstrings;
|
extern crate fstrings;
|
||||||
|
|
||||||
pub mod ast;
|
|
||||||
mod lalrpop {
|
mod lalrpop {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests;
|
pub mod tests;
|
||||||
|
|
||||||
// aqua is auto-generated, so exclude it from `cargo fmt -- --check`
|
// aqua is auto-generated, so exclude it from `cargo fmt -- --check`
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
mod aqua;
|
pub mod aqua;
|
||||||
mod parser;
|
pub mod parser;
|
||||||
|
|
||||||
pub use parser::parse;
|
|
||||||
}
|
}
|
||||||
|
pub mod ast;
|
||||||
|
|
||||||
pub use lalrpop::parse;
|
pub use lalrpop::parser::parse;
|
||||||
|
|
||||||
|
// #[cfg(test)]
|
||||||
|
pub use lalrpop::aqua::InstrParser;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user