mirror of
https://github.com/askama-rs/askama.git
synced 2025-09-27 13:00:57 +00:00
Add throughput to derive benchmark
This commit is contained in:
parent
4c0398ad67
commit
704a33beda
@ -23,7 +23,7 @@ required-features = ["__standalone"]
|
|||||||
parser = { package = "askama_parser", version = "=0.13.0", path = "../askama_parser" }
|
parser = { package = "askama_parser", version = "=0.13.0", path = "../askama_parser" }
|
||||||
|
|
||||||
basic-toml = { version = "0.1.1", optional = true }
|
basic-toml = { version = "0.1.1", optional = true }
|
||||||
pulldown-cmark = { version = "0.12.0", optional = true, default-features = false }
|
pulldown-cmark = { version = "0.13.0", optional = true, default-features = false }
|
||||||
serde = { version = "1.0", optional = true }
|
serde = { version = "1.0", optional = true }
|
||||||
serde_derive = { version = "1.0", optional = true }
|
serde_derive = { version = "1.0", optional = true }
|
||||||
|
|
||||||
|
@ -1,30 +1,37 @@
|
|||||||
use criterion::{BatchSize, Criterion, criterion_group, criterion_main};
|
use criterion::{BatchSize, Criterion, Throughput, criterion_group, criterion_main};
|
||||||
use quote::quote;
|
use quote::quote;
|
||||||
|
|
||||||
criterion_main!(benches);
|
criterion_main!(benches);
|
||||||
criterion_group!(benches, hello_world, librustdoc);
|
criterion_group!(benches, hello_world, librustdoc);
|
||||||
|
|
||||||
fn hello_world(c: &mut Criterion) {
|
fn hello_world(c: &mut Criterion) {
|
||||||
|
let source = "<html><body><h1>Hello, {{user}}!</h1></body></html>";
|
||||||
let ts = quote! {
|
let ts = quote! {
|
||||||
#[derive(Template)]
|
#[derive(Template)]
|
||||||
#[template(
|
#[template(
|
||||||
source = "<html><body><h1>Hello, {{user}}!</h1></body></html>",
|
source = #source,
|
||||||
ext = "html"
|
ext = "html"
|
||||||
)]
|
)]
|
||||||
struct Hello<'a> {
|
struct Hello<'a> {
|
||||||
user: &'a str,
|
user: &'a str,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
c.bench_function("hello_world", |b| {
|
|
||||||
|
let mut g = c.benchmark_group("synthetic");
|
||||||
|
g.throughput(Throughput::Bytes(source.len().try_into().unwrap()));
|
||||||
|
g.bench_function("hello_world", |b| {
|
||||||
b.iter_batched(
|
b.iter_batched(
|
||||||
|| ts.clone(),
|
|| ts.clone(),
|
||||||
askama_derive_standalone::derive_template,
|
askama_derive_standalone::derive_template,
|
||||||
BatchSize::LargeInput,
|
BatchSize::LargeInput,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
g.finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn librustdoc(c: &mut Criterion) {
|
fn librustdoc(c: &mut Criterion) {
|
||||||
|
let mut g = c.benchmark_group("librustdoc");
|
||||||
|
|
||||||
macro_rules! benches {
|
macro_rules! benches {
|
||||||
($($name:expr => $struct:item)*) => { $({
|
($($name:expr => $struct:item)*) => { $({
|
||||||
const SOURCE: &str =
|
const SOURCE: &str =
|
||||||
@ -35,7 +42,8 @@ fn librustdoc(c: &mut Criterion) {
|
|||||||
#[template(source = #SOURCE, ext = "html")]
|
#[template(source = #SOURCE, ext = "html")]
|
||||||
$struct
|
$struct
|
||||||
};
|
};
|
||||||
c.bench_function($name, |b| {
|
g.throughput(Throughput::Bytes(SOURCE.len().try_into().unwrap()));
|
||||||
|
g.bench_function($name, |b| {
|
||||||
b.iter_batched(
|
b.iter_batched(
|
||||||
|| ts.clone(),
|
|| ts.clone(),
|
||||||
askama_derive_standalone::derive_template,
|
askama_derive_standalone::derive_template,
|
||||||
@ -133,4 +141,5 @@ fn librustdoc(c: &mut Criterion) {
|
|||||||
size: u64,
|
size: u64,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
g.finish();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user