#![feature(test)] extern crate serde; extern crate test; #[macro_use] extern crate serde_derive; extern crate torrust_serde_bencode; use serde::Serialize; use test::Bencher; use torrust_serde_bencode::de::from_bytes; use torrust_serde_bencode::ser::Serializer; #[bench] fn ser_de_simple(b: &mut Bencher) { #[derive(Serialize, Deserialize)] struct Fake { a: i64, b: i64, } b.iter(|| { let a = Fake { a: 2, b: 7 }; let mut ser = Serializer::new(); a.serialize(&mut ser).unwrap(); let b: Fake = from_bytes(ser.as_ref()).unwrap(); b }); } #[bench] fn ser_de_nested(b: &mut Bencher) { #[derive(Serialize, Deserialize)] struct FakeA { a: i64, b: i64, } #[derive(Serialize, Deserialize)] struct FakeB { a: i64, b: FakeA, } b.iter(|| { let a = FakeB { a: 2, b: FakeA { a: 7, b: 9 }, }; let mut ser = Serializer::new(); a.serialize(&mut ser).unwrap(); let b: FakeB = from_bytes(ser.as_ref()).unwrap(); b }); }