rtiow: buffer json output, waaay faster.

This commit is contained in:
Bill Thiede 2019-10-30 20:04:18 -07:00
parent 6bd29a2152
commit f965a00e0c

View File

@ -1,5 +1,6 @@
use std::collections::HashMap; use std::collections::HashMap;
use std::fs::File; use std::fs::File;
use std::io::BufWriter;
use std::path::Path; use std::path::Path;
use std::sync::Arc; use std::sync::Arc;
use std::sync::Mutex; use std::sync::Mutex;
@ -189,6 +190,7 @@ pub fn write_images<P: AsRef<Path>>(
}; };
info!("Saving {}", binary_path.to_string_lossy()); info!("Saving {}", binary_path.to_string_lossy());
let f = File::create(output_dir.join(binary_path))?; let f = File::create(output_dir.join(binary_path))?;
let f = BufWriter::new(f);
match it { match it {
ImageType::RGB01 => { ImageType::RGB01 => {
serde_json::ser::to_writer( serde_json::ser::to_writer(
@ -200,12 +202,12 @@ pub fn write_images<P: AsRef<Path>>(
)?; )?;
} }
ImageType::Grey01 | ImageType::GreyNormalized => { ImageType::Grey01 | ImageType::GreyNormalized => {
// TODO(wathiede): make grey scale
serde_json::ser::to_writer(f, &img.pix.iter().map(|v| v.x).collect::<Vec<f32>>())?; serde_json::ser::to_writer(f, &img.pix.iter().map(|v| v.x).collect::<Vec<f32>>())?;
} }
}; };
} }
let f = File::create(output_dir.join("data.json"))?; let f = File::create(output_dir.join("data.json"))?;
let f = BufWriter::new(f);
serde_json::ser::to_writer( serde_json::ser::to_writer(
f, f,
&Data { &Data {