Skip to content

Commit

Permalink
PR #29 Allow rendering borrowed events
Browse files Browse the repository at this point in the history
Merge branch 'render_ref'

closes #29
  • Loading branch information
hellux committed Mar 25, 2023
2 parents 76c2c1d + d285420 commit 0884be2
Show file tree
Hide file tree
Showing 8 changed files with 585 additions and 444 deletions.
62 changes: 59 additions & 3 deletions bench/criterion/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ fn gen_html(c: &mut criterion::Criterion) {
|| jotdown::Parser::new(input).collect::<Vec<_>>(),
|p| {
let mut s = String::new();
jotdown::html::Renderer.push(p.into_iter(), &mut s).unwrap();
jotdown::html::Renderer::default()
.push(p.into_iter(), &mut s)
.unwrap();
s
},
criterion::BatchSize::SmallInput,
Expand All @@ -62,6 +64,60 @@ fn gen_html(c: &mut criterion::Criterion) {
}
criterion_group!(html, gen_html);

fn gen_html_borrow(c: &mut criterion::Criterion) {
let mut group = c.benchmark_group("html_borrow");
for (name, input) in bench_input::INPUTS {
group.throughput(criterion::Throughput::Elements(
jotdown::Parser::new(input).count() as u64,
));
group.bench_with_input(
criterion::BenchmarkId::from_parameter(name),
input,
|b, &input| {
b.iter_batched(
|| jotdown::Parser::new(input).collect::<Vec<_>>(),
|p| {
let mut s = String::new();
jotdown::html::Renderer::default()
.push_borrowed(p.as_slice().iter(), &mut s)
.unwrap();
s
},
criterion::BatchSize::SmallInput,
);
},
);
}
}
criterion_group!(html_borrow, gen_html_borrow);

fn gen_html_clone(c: &mut criterion::Criterion) {
let mut group = c.benchmark_group("html_clone");
for (name, input) in bench_input::INPUTS {
group.throughput(criterion::Throughput::Elements(
jotdown::Parser::new(input).count() as u64,
));
group.bench_with_input(
criterion::BenchmarkId::from_parameter(name),
input,
|b, &input| {
b.iter_batched(
|| jotdown::Parser::new(input).collect::<Vec<_>>(),
|p| {
let mut s = String::new();
jotdown::html::Renderer::default()
.push(p.iter().cloned(), &mut s)
.unwrap();
s
},
criterion::BatchSize::SmallInput,
);
},
);
}
}
criterion_group!(html_clone, gen_html_clone);

fn gen_full(c: &mut criterion::Criterion) {
let mut group = c.benchmark_group("full");
for (name, input) in bench_input::INPUTS {
Expand All @@ -72,7 +128,7 @@ fn gen_full(c: &mut criterion::Criterion) {
|b, &input| {
b.iter_with_large_drop(|| {
let mut s = String::new();
jotdown::html::Renderer
jotdown::html::Renderer::default()
.push(jotdown::Parser::new(input), &mut s)
.unwrap();
s
Expand All @@ -83,4 +139,4 @@ fn gen_full(c: &mut criterion::Criterion) {
}
criterion_group!(full, gen_full);

criterion_main!(block, inline, html, full);
criterion_main!(block, inline, html, html_borrow, html_clone, full);
2 changes: 1 addition & 1 deletion bench/iai/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fn block_inline() -> Option<jotdown::Event<'static>> {

fn full() -> String {
let mut s = String::new();
jotdown::html::Renderer
jotdown::html::Renderer::default()
.push(jotdown::Parser::new(bench_input::ALL), &mut s)
.unwrap();
s
Expand Down
4 changes: 3 additions & 1 deletion examples/jotdown_wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ use jotdown::Render;
pub fn jotdown_render(djot: &str) -> String {
let events = jotdown::Parser::new(djot);
let mut html = String::new();
jotdown::html::Renderer.push(events, &mut html).unwrap();
jotdown::html::Renderer::default()
.push(events, &mut html)
.unwrap();
html
}
Loading

0 comments on commit 0884be2

Please sign in to comment.