flesh out struct benchmarks

This commit is contained in:
Erick Tryzelaar 2014-05-25 22:20:06 -07:00
parent 62fb2073e2
commit 41eb7293d2
2 changed files with 82 additions and 4 deletions

View File

@ -438,6 +438,40 @@ mod deserializer {
}
}
#[bench]
fn bench_struct_decoder_outer_empty(b: &mut Bencher) {
b.iter(|| {
let mut map = HashMap::new();
map.insert("abc".to_strbuf(), Some('c'));
let outer = Outer {
inner: vec!(),
};
let mut d = decoder::OuterDecoder::new(outer.clone());
let value: Outer = Decodable::decode(&mut d).unwrap();
assert_eq!(value, outer);
})
}
#[bench]
fn bench_struct_deserializer_outer_empty(b: &mut Bencher) {
b.iter(|| {
let mut map = HashMap::new();
map.insert("abc".to_strbuf(), Some('c'));
let outer = Outer {
inner: vec!(),
};
let mut d = deserializer::OuterDeserializer::new(outer.clone());
let value: Outer = Deserializable::deserialize(&mut d).unwrap();
assert_eq!(value, outer);
})
}
#[bench]
fn bench_struct_decoder(b: &mut Bencher) {
b.iter(|| {
@ -483,3 +517,47 @@ fn bench_struct_deserializer(b: &mut Bencher) {
assert_eq!(value, outer);
})
}
#[bench]
fn bench_struct_decoder_inner_empty(b: &mut Bencher) {
b.iter(|| {
let mut map = HashMap::new();
let outer = Outer {
inner: vec!(
Inner {
a: (),
b: 5,
c: map,
},
)
};
let mut d = decoder::OuterDecoder::new(outer.clone());
let value: Outer = Decodable::decode(&mut d).unwrap();
assert_eq!(value, outer);
})
}
#[bench]
fn bench_struct_deserializerinner_empty(b: &mut Bencher) {
b.iter(|| {
let mut map = HashMap::new();
let outer = Outer {
inner: vec!(
Inner {
a: (),
b: 5,
c: map,
},
)
};
let mut d = deserializer::OuterDeserializer::new(outer.clone());
let value: Outer = Deserializable::deserialize(&mut d).unwrap();
assert_eq!(value, outer);
})
}

View File

@ -17,11 +17,11 @@ pub mod de;
//#[cfg(test)]
//pub mod bench_bytes;
#[cfg(test)]
pub mod bench_enum;
//#[cfg(test)]
//pub mod bench_enum;
#[cfg(test)]
pub mod bench_struct;
#[cfg(test)]
pub mod bench_vec;
//#[cfg(test)]
//pub mod bench_vec;