use std::borrow::Cow; use bencher::Bencher; use bencher::{benchmark_group, benchmark_main}; use instant_xml::{from_str, FromXml}; fn decode_short_ascii(bench: &mut Bencher) { let xml = "foobar"; bench.iter(|| { from_str::(xml).unwrap(); }) } fn decode_longer_ascii(bench: &mut Bencher) { let mut xml = String::with_capacity(4096); xml.push_str(""); for _ in 0..64 { xml.push_str("abcdefghijklmnopqrstuvwxyz"); xml.push_str("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); xml.push_str("0123456789"); } xml.push_str(""); bench.iter(|| { from_str::(&xml).unwrap(); }) } fn decode_short_escaped(bench: &mut Bencher) { let xml = "foo & bar"; bench.iter(|| { from_str::(xml).unwrap(); }) } fn decode_longer_escaped(bench: &mut Bencher) { let mut xml = String::with_capacity(4096); xml.push_str(""); for _ in 0..64 { xml.push_str("abcdefghijklmnopqrstuvwxyz"); xml.push_str("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); xml.push_str("0123456789"); xml.push_str("""); } xml.push_str(""); bench.iter(|| { from_str::(&xml).unwrap(); }) } #[derive(Debug, FromXml)] struct Element<'a> { #[allow(dead_code)] inner: Cow<'a, str>, } benchmark_group!( benches, decode_short_ascii, decode_longer_ascii, decode_short_escaped, decode_longer_escaped, ); benchmark_main!(benches);