From aae03356cb3985fd10e440c0737172232e05829d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Lecrenier?= Date: Wed, 6 Jul 2022 18:20:15 +0200 Subject: [PATCH] Use BufReader to read datasets in benchmarks --- benchmarks/benches/utils.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/benchmarks/benches/utils.rs b/benchmarks/benches/utils.rs index f79d925e7..b2a9966a2 100644 --- a/benchmarks/benches/utils.rs +++ b/benchmarks/benches/utils.rs @@ -140,9 +140,10 @@ pub fn run_benches(c: &mut criterion::Criterion, confs: &[Conf]) { } } -pub fn documents_from(filename: &str, filetype: &str) -> DocumentBatchReader { +pub fn documents_from(filename: &str, filetype: &str) -> DocumentBatchReader { let reader = File::open(filename).expect(&format!("could not find the dataset in: {}", filename)); + let reader = BufReader::new(reader); let documents = match filetype { "csv" => documents_from_csv(reader).unwrap(), "json" => documents_from_json(reader).unwrap(), @@ -152,12 +153,11 @@ pub fn documents_from(filename: &str, filetype: &str) -> DocumentBatchReader anyhow::Result> { +fn documents_from_jsonl(mut reader: impl BufRead) -> anyhow::Result> { let mut writer = Cursor::new(Vec::new()); let mut documents = milli::documents::DocumentBatchBuilder::new(&mut writer)?; let mut buf = String::new(); - let mut reader = BufReader::new(reader); while reader.read_line(&mut buf)? > 0 { documents.extend_from_json(&mut buf.as_bytes())?; @@ -168,7 +168,7 @@ fn documents_from_jsonl(reader: impl Read) -> anyhow::Result> { Ok(writer.into_inner()) } -fn documents_from_json(reader: impl Read) -> anyhow::Result> { +fn documents_from_json(reader: impl BufRead) -> anyhow::Result> { let mut writer = Cursor::new(Vec::new()); let mut documents = milli::documents::DocumentBatchBuilder::new(&mut writer)?; @@ -178,7 +178,7 @@ fn documents_from_json(reader: impl Read) -> anyhow::Result> { Ok(writer.into_inner()) } -fn documents_from_csv(reader: impl Read) -> anyhow::Result> { +fn documents_from_csv(reader: impl BufRead) -> anyhow::Result> { let mut writer = Cursor::new(Vec::new()); milli::documents::DocumentBatchBuilder::from_csv(reader, &mut writer)?.finish()?;