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 and return value on op
Browse files Browse the repository at this point in the history
  • Loading branch information
ematipico committed Feb 1, 2022
1 parent a4b3824 commit ec1d052
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 22 deletions.
8 changes: 4 additions & 4 deletions xtask/bench/src/features/formatter.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::BenchmarkSummary;
use rome_formatter::{format, FormatOptions};
use rome_formatter::{format, FormatOptions, Formatted};
use rslint_parser::SyntaxNode;
use std::fmt::{Display, Formatter};
use std::time::Duration;
Expand All @@ -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,8 +20,8 @@ pub fn benchmark_format_lib(id: &str, root: SyntaxNode) -> BenchmarkSummary {
})
}

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

impl FormatterMeasurement {
Expand Down
7 changes: 4 additions & 3 deletions xtask/bench/src/features/parser.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use crate::BenchmarkSummary;
use itertools::Itertools;
use rslint_errors::Diagnostic;
use rslint_parser::Syntax;
use rslint_parser::ast::JsAnyRoot;
use rslint_parser::{Parse, Syntax};
use std::fmt::{Display, Formatter};
use std::ops::Add;
use std::time::Duration;
Expand Down Expand Up @@ -98,9 +99,9 @@ pub fn benchmark_parse_lib(id: &str, code: &str) -> BenchmarkSummary {
})
}

pub fn run_parse(code: &str) {
pub fn run_parse(code: &str) -> Parse<JsAnyRoot> {
let syntax = Syntax::default().module();
rslint_parser::parse(code, 0, syntax);
rslint_parser::parse(code, 0, syntax)
}

impl ParseMeasurement {
Expand Down
24 changes: 9 additions & 15 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 @@ -100,20 +99,15 @@ pub fn run(filter: String, criterion: bool, baseline: Option<String>, feature: F
group.throughput(criterion::Throughput::Bytes(code.len() as u64));
group.bench_function(&id, |b| match feature {
FeatureToBenchmark::Parser => b.iter(|| {
#[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 +119,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 +129,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 ec1d052

Please sign in to comment.