Small fix to xml bench
@@ -4,6 +4,7 @@ use curiefense::requestfields::RequestField;
use criterion::*;
use std::collections::HashMap;
+use std::fmt::Write;
fn body_test(mcontent_type: Option<&str>, body: &[u8], expected_size: Option<usize>) {
let mut logs = Logs::default();
@@ -49,20 +50,20 @@ fn json_string_map(c: &mut Criterion) {
}
}
-fn create_xml_string_map(sz: usize) -> String {
+fn create_xml_string_map(sz: usize) -> anyhow::Result<String> {
let mut out = "<toplevel>".to_string();
for i in 0..sz {
- out += &format!("<b{}>{}</b{}>", i, i, i);
+ write!(&mut out, "<b{}>{}</b{}>", i, i, i)?;
}
out += "</toplevel>";
- out
+ Ok(out)
}
fn xml_string_map(c: &mut Criterion) {
let mut group = c.benchmark_group("XML map");
for sz in [1, 100, 10000].iter() {
group.bench_with_input(BenchmarkId::from_parameter(sz), sz, |b, &size| {
- let mp = create_xml_string_map(size);
+ let mp = create_xml_string_map(size).unwrap();
b.iter(|| body_test(Some("text/xml"), black_box(mp.as_bytes()), None))
});
}
