summaryrefslogtreecommitdiffstats
path: root/crates
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2024-04-21 17:08:25 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2024-04-22 17:53:49 +0200
commita0853a06d3e729ddfd93caa05f9581d00f5d30bf (patch)
tree47287b00d675418b4d0c8996800cdc6bb7278f7b /crates
parent767842ab64f601b324b02a0f7f55ebc0b849f251 (diff)
downloadrebel-a0853a06d3e729ddfd93caa05f9581d00f5d30bf.tar
rebel-a0853a06d3e729ddfd93caa05f9581d00f5d30bf.zip
rebel-parse: add benchmark
Diffstat (limited to 'crates')
-rw-r--r--crates/rebel-parse/Cargo.toml5
-rw-r--r--crates/rebel-parse/benches/recipe.rs21
2 files changed, 26 insertions, 0 deletions
diff --git a/crates/rebel-parse/Cargo.toml b/crates/rebel-parse/Cargo.toml
index 3ed7d98..b87ba3f 100644
--- a/crates/rebel-parse/Cargo.toml
+++ b/crates/rebel-parse/Cargo.toml
@@ -14,3 +14,8 @@ peg = "0.8.2"
[dev-dependencies]
clap = { version = "4.0.0", features = ["derive"] }
+divan = "0.1.14"
+
+[[bench]]
+name = "recipe"
+harness = false
diff --git a/crates/rebel-parse/benches/recipe.rs b/crates/rebel-parse/benches/recipe.rs
new file mode 100644
index 0000000..08eab7d
--- /dev/null
+++ b/crates/rebel-parse/benches/recipe.rs
@@ -0,0 +1,21 @@
+use rebel_parse::{ast, token::Token};
+
+fn main() {
+ divan::main();
+}
+
+const RECIPE: &str = include_str!("../../../examples/recipes/gmp/build.recipe");
+
+#[divan::bench]
+fn tokenize() -> Vec<Token<'static>> {
+ rebel_parse::tokenize::token_stream(divan::black_box(RECIPE)).unwrap()
+}
+
+#[divan::bench]
+fn parse(bencher: divan::Bencher) {
+ let tokens = tokenize();
+
+ bencher.bench(|| -> ast::Recipe<'static> {
+ rebel_parse::recipe::recipe(divan::black_box(&tokens)).unwrap()
+ });
+}