2 ms·
FYI you can read directly from a file without reading into a buf first. This might be a bit faster: let json_file = File::open(json_file_path).expect("file
by terhechte 7y ago
FYI you can read directly from a file without reading into a buf first. This might be a bit faster:
let json_file = File::open(json_file_path).expect("file not found");
let deserialized_camera: SomeDataType =
serde_json::from_reader(json_file).expect("error while reading json");
- zuzun 7y agoA year ago I did some benchmarks and found that from_reader is much slower than from_slice. There's now a note in the serde_json docs, so it still seems to be an issue. I guess std::fs::read + serde_json::from_slice is the fastest way to do it, because it avoids the from_reader slowness and an UTF-8 validation.
- terhechte 7y agoThanks for the info, good to know!