Skip to content

Commit

Permalink
Merge pull request #236 from epage/clean
Browse files Browse the repository at this point in the history
style(bench): Modernize checks bench
  • Loading branch information
epage authored Apr 30, 2021
2 parents e4f4777 + c2e3989 commit af1324f
Showing 1 changed file with 14 additions and 30 deletions.
44 changes: 14 additions & 30 deletions benches/checks.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
mod data;

use assert_fs::prelude::*;
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput};
use typos_cli::file::FileChecker;

fn bench_checks(c: &mut Criterion) {
Expand All @@ -11,14 +11,16 @@ fn bench_checks(c: &mut Criterion) {
.dict(&dict)
.tokenizer(&tokenizer);

let mut group = c.benchmark_group("checks");
let temp = assert_fs::TempDir::new().unwrap();

let mut group = c.benchmark_group("check_file");
for (name, sample) in data::DATA {
let len = sample.len();
group.bench_with_input(BenchmarkId::new("files", name), &len, |b, _| {
let temp = assert_fs::TempDir::new().unwrap();
let sample_path = temp.child("sample");
sample_path.write_str(sample).unwrap();
let sample_path = temp.child(name);
sample_path.write_str(sample).unwrap();

let len = sample.len();
group.throughput(Throughput::Bytes(len as u64));
group.bench_with_input(BenchmarkId::new("FoundFiles", name), &len, |b, _| {
b.iter(|| {
typos_cli::file::FoundFiles.check_file(
sample_path.path(),
Expand All @@ -27,14 +29,8 @@ fn bench_checks(c: &mut Criterion) {
&typos_cli::report::PrintSilent,
)
});

temp.close().unwrap();
});
group.bench_with_input(BenchmarkId::new("identifiers", name), &len, |b, _| {
let temp = assert_fs::TempDir::new().unwrap();
let sample_path = temp.child("sample");
sample_path.write_str(sample).unwrap();

group.bench_with_input(BenchmarkId::new("Identifiers", name), &len, |b, _| {
b.iter(|| {
typos_cli::file::Identifiers.check_file(
sample_path.path(),
Expand All @@ -43,14 +39,8 @@ fn bench_checks(c: &mut Criterion) {
&typos_cli::report::PrintSilent,
)
});

temp.close().unwrap();
});
group.bench_with_input(BenchmarkId::new("words", name), &len, |b, _| {
let temp = assert_fs::TempDir::new().unwrap();
let sample_path = temp.child("sample");
sample_path.write_str(sample).unwrap();

group.bench_with_input(BenchmarkId::new("Words", name), &len, |b, _| {
b.iter(|| {
typos_cli::file::Words.check_file(
sample_path.path(),
Expand All @@ -59,14 +49,8 @@ fn bench_checks(c: &mut Criterion) {
&typos_cli::report::PrintSilent,
)
});

temp.close().unwrap();
});
group.bench_with_input(BenchmarkId::new("typos", name), &len, |b, _| {
let temp = assert_fs::TempDir::new().unwrap();
let sample_path = temp.child("sample");
sample_path.write_str(sample).unwrap();

group.bench_with_input(BenchmarkId::new("Typos", name), &len, |b, _| {
b.iter(|| {
typos_cli::file::Typos.check_file(
sample_path.path(),
Expand All @@ -75,11 +59,11 @@ fn bench_checks(c: &mut Criterion) {
&typos_cli::report::PrintSilent,
)
});

temp.close().unwrap();
});
}
group.finish();

temp.close().unwrap();
}

criterion_group!(benches, bench_checks,);
Expand Down

0 comments on commit af1324f

Please sign in to comment.