-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #397 from YuukiToriyama/feature/refactor-orthograp…
…hical-variant-adapter/add-benchmark 表記ゆれアダプタのリファクタ: `OrthographicVariantAdapter`に対するベンチマークテストを作成
- Loading branch information
Showing
4 changed files
with
61 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
mod orthographical_variant_adapter; | ||
|
||
use crate::orthographical_variant_adapter::bench_orthographical_variant_adapter; | ||
use criterion::{criterion_group, criterion_main}; | ||
|
||
criterion_group!(benches, bench_orthographical_variant_adapter); | ||
criterion_main!(benches); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
use criterion::measurement::WallTime; | ||
use criterion::{BatchSize, BenchmarkGroup, BenchmarkId, Criterion}; | ||
use japanese_address_parser::parser::adapter::orthographical_variant_adapter::{ | ||
OrthographicalVariantAdapter, OrthographicalVariants, Variant, | ||
}; | ||
|
||
pub fn bench_orthographical_variant_adapter(c: &mut Criterion) { | ||
let mut group = c.benchmark_group("orthographical_variant_adapter"); | ||
add_tests( | ||
&mut group, | ||
TestSuite { | ||
expected: "松ケ崎東池ノ内町", | ||
inputs: vec![ | ||
"松が崎東池ノ内町", | ||
"松ヶ崎東池ノ内町", | ||
"松ケ﨑東池ノ内町", | ||
"松ケ﨑東池の内町", | ||
"松ガ﨑東池の内町", | ||
], | ||
variants_to_be_used: vec![Variant::ケ, Variant::崎, Variant::の], | ||
}, | ||
); | ||
group.finish(); | ||
} | ||
|
||
fn add_tests(group: &mut BenchmarkGroup<WallTime>, test_suite: TestSuite) { | ||
for input in test_suite.inputs { | ||
let benchmark_id = BenchmarkId::new(test_suite.expected, input); | ||
group.bench_with_input(benchmark_id, input, |b, input| { | ||
b.iter_batched( | ||
|| OrthographicalVariantAdapter { | ||
variant_list: test_suite.variants_to_be_used.clone(), | ||
}, | ||
|adapter| { | ||
let (region_name, _) = adapter.apply(input, test_suite.expected).unwrap(); | ||
assert_eq!(region_name, test_suite.expected); | ||
}, | ||
BatchSize::SmallInput, | ||
) | ||
}); | ||
} | ||
} | ||
|
||
struct TestSuite { | ||
expected: &'static str, | ||
inputs: Vec<&'static str>, | ||
variants_to_be_used: Vec<Variant>, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters