diff --git a/Cargo.lock b/Cargo.lock index d0bbdcd..c85b251 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -34,6 +34,15 @@ dependencies = [ "jotdown", ] +[[package]] +name = "bench-iai" +version = "0.1.0" +dependencies = [ + "bench-input", + "iai", + "jotdown", +] + [[package]] name = "bench-input" version = "0.1.0" @@ -171,6 +180,12 @@ dependencies = [ "libc", ] +[[package]] +name = "iai" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71a816c97c42258aa5834d07590b718b4c9a598944cd39a52dc25b351185d678" + [[package]] name = "indexmap" version = "1.9.2" diff --git a/Cargo.toml b/Cargo.toml index 247c5bf..07e02e4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,6 +20,7 @@ exclude = [ [workspace] members = [ "bench/criterion", + "bench/iai", "bench/input", "examples/jotdown_wasm", ] diff --git a/bench/iai/Cargo.toml b/bench/iai/Cargo.toml new file mode 100644 index 0000000..8ec66ea --- /dev/null +++ b/bench/iai/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "bench-iai" +version = "0.1.0" +edition = "2021" + +[dev-dependencies] +iai = { version = "0.1", default-features = false } +bench-input = { path = "../input" } +jotdown = { path = "../../", features = ["html", "deterministic"] } + +[[bench]] +name = "iai" +path = "main.rs" +harness = false diff --git a/bench/iai/main.rs b/bench/iai/main.rs new file mode 100644 index 0000000..e606d5f --- /dev/null +++ b/bench/iai/main.rs @@ -0,0 +1,21 @@ +use iai::black_box; + +use jotdown::Render; + +fn block() -> jotdown::Parser<'static> { + jotdown::Parser::new(black_box(bench_input::ALL)) +} + +fn block_inline() -> Option> { + black_box(jotdown::Parser::new(black_box(bench_input::ALL))).last() +} + +fn full() -> String { + let mut s = String::new(); + jotdown::html::Renderer + .push(jotdown::Parser::new(bench_input::ALL), &mut s) + .unwrap(); + s +} + +iai::main!(block, block_inline, full);