-
-
Save tgnottingham/950569d1fd85d58116b32614bddcd03a to your computer and use it in GitHub Desktop.
serde_json::from_reader benchmark 2
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
use serde::{Deserialize, Serialize}; | |
#[derive(Clone, Deserialize, Serialize)] | |
struct Foo { | |
number: u32, | |
string: String, | |
vector: Vec<Bar>, | |
} | |
#[derive(Clone, Deserialize, Serialize)] | |
struct Bar { | |
float: f32, | |
string: String, | |
} | |
fn main() { | |
/* | |
let bars: Vec<_> = (0..100).map(|i| Bar { | |
float: i as f32, | |
string: "s".to_owned(), | |
}).collect(); | |
let foos: Vec<_> = (0..10000).map(|i| Foo { | |
number: i, | |
string: "this is a short string".to_owned(), | |
vector: bars.clone(), | |
}).collect(); | |
let v = serde_json::to_vec(&foos).unwrap(); | |
std::fs::write("foos.json", v).unwrap(); | |
*/ | |
let reader = std::fs::File::open("foos.json").unwrap(); | |
//let reader = std::io::BufReader::new(reader); | |
let foos: Vec<Foo> = serde_json::from_reader(reader).unwrap(); | |
println!("{}", foos.len()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment