diff --git a/instant-segment/benches/bench.rs b/instant-segment/benches/bench.rs index 1c0f960..bad6225 100644 --- a/instant-segment/benches/bench.rs +++ b/instant-segment/benches/bench.rs @@ -2,12 +2,15 @@ use bencher::{benchmark_group, benchmark_main, Bencher}; +use instant_segment::test_data::{crate_data_dir, segmenter}; +use instant_segment::Search; + benchmark_group!(benches, short); benchmark_main!(benches); fn short(bench: &mut Bencher) { - let segmenter = instant_segment::test_data::segmenter(); - let mut search = instant_segment::Search::default(); + let segmenter = segmenter(crate_data_dir()); + let mut search = Search::default(); bench.iter(|| { let _ = segmenter.segment("thisisatest", &mut search); }); diff --git a/instant-segment/src/test_data.rs b/instant-segment/src/test_data.rs index dfd666e..08e88d7 100644 --- a/instant-segment/src/test_data.rs +++ b/instant-segment/src/test_data.rs @@ -9,11 +9,10 @@ use super::{HashMap, Segmenter}; #[test] fn test_data() { - crate::test_cases::run(&segmenter()); + crate::test_cases::run(&segmenter(crate_data_dir())); } -pub fn segmenter() -> Segmenter { - let dir = PathBuf::from(format!("{}/../data", env!("CARGO_MANIFEST_DIR"))); +pub fn segmenter(dir: PathBuf) -> Segmenter { let mut ln = String::new(); let uni_file = dir.join("en-unigrams.txt"); @@ -59,3 +58,7 @@ pub fn segmenter() -> Segmenter { Segmenter::from_maps(unigrams, bigrams) } + +pub fn crate_data_dir() -> PathBuf { + PathBuf::from(format!("{}/../data", env!("CARGO_MANIFEST_DIR"))) +}