Skip to content

Commit

Permalink
bench: add full_bench benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
phoenix-ru committed Oct 19, 2023
1 parent 0f4a9b7 commit 7f62567
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 14 deletions.
4 changes: 4 additions & 0 deletions crates/fervid/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,7 @@ harness = false
[[bench]]
name = "codegen_bench"
harness = false

[[bench]]
name = "full_bench"
harness = false
11 changes: 4 additions & 7 deletions crates/fervid/benches/codegen_bench.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
use criterion::{criterion_group, criterion_main, Criterion, BenchmarkId};
use swc_core::common::DUMMY_SP;

fn codegen_benchmark(c: &mut Criterion) {
let inputs = vec![
("input.vue", include_str!("./fixtures/input.vue")),
("ElTable.vue", include_str!("./fixtures/ElTable.vue")),
("TodoApp.vue", include_str!("./fixtures/TodoApp.vue")),
];
mod fixtures;
use fixtures::FIXTURES;

for (name, component) in inputs {
fn codegen_benchmark(c: &mut Criterion) {
for (name, component) in FIXTURES {
c.bench_with_input(BenchmarkId::new("codegen: generate CSR+DEV", name), &component, |b, component| {
let mut errors = Vec::new();
let res = fervid_parser::parse_sfc(component, &mut errors);
Expand Down
11 changes: 11 additions & 0 deletions crates/fervid/benches/fixtures/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
macro_rules! input {
($name: literal) => {
($name, include_str!(concat!("./", $name)))
};
}

pub const FIXTURES: [(&str, &str); 3] = [
input!("input.vue"),
input!("ElTable.vue"),
input!("TodoApp.vue"),
];
21 changes: 21 additions & 0 deletions crates/fervid/benches/full_bench.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use criterion::{criterion_group, criterion_main, Criterion, BenchmarkId};

mod fixtures;
use fixtures::FIXTURES;

fn full_compile_benchmark(c: &mut Criterion) {
for (name, component) in FIXTURES {
c.bench_with_input(BenchmarkId::new("compile_sync_naive", name), &component, |b, component| {
b.iter_batched(
|| (),
|_| {
let _ = fervid::compile_sync_naive(component);
},
criterion::BatchSize::SmallInput,
);
});
}
}

criterion_group!(benches, full_compile_benchmark);
criterion_main!(benches);
11 changes: 4 additions & 7 deletions crates/fervid/benches/parser_bench.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion};

fn parser_benchmark(c: &mut Criterion) {
let inputs = vec![
("input.vue", include_str!("./fixtures/input.vue")),
("ElTable.vue", include_str!("./fixtures/ElTable.vue")),
("TodoApp.vue", include_str!("./fixtures/TodoApp.vue")),
];
mod fixtures;
use fixtures::FIXTURES;

for input in inputs {
fn parser_benchmark(c: &mut Criterion) {
for input in FIXTURES {
c.bench_with_input(
BenchmarkId::new("parser: new parse", input.0),
&input.1,
Expand Down

0 comments on commit 7f62567

Please sign in to comment.