Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

Commit

Permalink
fix: revisit black box call
Browse files Browse the repository at this point in the history
  • Loading branch information
ematipico committed Feb 1, 2022
1 parent a4b3824 commit b20fa66
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
4 changes: 2 additions & 2 deletions xtask/bench/src/features/formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub struct FormatterMeasurement {
id: String,
formatting: Duration,
}
pub fn benchmark_format_lib(id: &str, root: SyntaxNode) -> BenchmarkSummary {
pub fn benchmark_format_lib(id: &str, root: &SyntaxNode) -> BenchmarkSummary {
let formatter_timer = timing::start();
run_format(root);
let formatter_duration = formatter_timer.stop();
Expand All @@ -20,7 +20,7 @@ pub fn benchmark_format_lib(id: &str, root: SyntaxNode) -> BenchmarkSummary {
})
}

pub fn run_format(root: SyntaxNode) {
pub fn run_format(root: &SyntaxNode) {
format(FormatOptions::default(), &root).unwrap();
}

Expand Down
23 changes: 9 additions & 14 deletions xtask/bench/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
mod features;
mod utils;

use criterion::BatchSize;
use rslint_parser::{parse, Syntax};
use std::fmt::{Display, Formatter};
use std::str::FromStr;
Expand Down Expand Up @@ -103,17 +102,13 @@ pub fn run(filter: String, criterion: bool, baseline: Option<String>, feature: F
#[allow(clippy::unit_arg)]
criterion::black_box(run_parse(code));
}),
FeatureToBenchmark::Formatter => b.iter_batched(
|| {
let syntax = Syntax::default().module();
parse(code, 0, syntax).syntax()
},
|root| {
#[allow(clippy::unit_arg)]
criterion::black_box(run_format(root));
},
BatchSize::PerIteration,
),
FeatureToBenchmark::Formatter => {
let syntax = Syntax::default().module();
let root = parse(code, 0, syntax).syntax();
b.iter(|| {
criterion::black_box(run_format(&root));
})
}
});
group.finish();
} else {
Expand All @@ -125,7 +120,7 @@ pub fn run(filter: String, criterion: bool, baseline: Option<String>, feature: F
FeatureToBenchmark::Formatter => {
let syntax = Syntax::default().module();
let root = parse(code, 0, syntax).syntax();
run_format(root);
run_format(&root);
}
}
}
Expand All @@ -135,7 +130,7 @@ pub fn run(filter: String, criterion: bool, baseline: Option<String>, feature: F
FeatureToBenchmark::Formatter => {
let syntax = Syntax::default().module();
let root = parse(code, 0, syntax).syntax();
benchmark_format_lib(&id, root)
benchmark_format_lib(&id, &root)
}
};

Expand Down

0 comments on commit b20fa66

Please sign in to comment.