55 lines
2.1 KiB
Rust
55 lines
2.1 KiB
Rust
use super::*;
|
|
use std::{collections::BTreeMap, hint::black_box, time::Instant};
|
|
|
|
#[test]
|
|
#[ignore = "explicit release performance probe"]
|
|
fn multipart_field_cost() {
|
|
let directory = Directory::new();
|
|
Runtime::new(TaskLimits::default())
|
|
.unwrap()
|
|
.run(async |scope| {
|
|
println!("\ncase,sample,iterations,elapsed_ns,checksum");
|
|
for count in [1, 16, 64] {
|
|
let mut source = String::new();
|
|
for index in 0..count {
|
|
source.push_str(&format!(
|
|
"--boundary\r\nContent-Disposition: form-data; name=field{index}\r\n\r\n{}\r\n",
|
|
"a".repeat(64)
|
|
));
|
|
}
|
|
source.push_str("--boundary--\r\n");
|
|
let bytes = Bytes::from(source);
|
|
let limits = Limits {
|
|
fields: count,
|
|
parts: count,
|
|
..Limits::default()
|
|
};
|
|
for sample in 0..15 {
|
|
let started = Instant::now();
|
|
let mut checksum = 0;
|
|
for _ in 0..1000 {
|
|
let multipart = upload::decode(
|
|
http_body_util::Full::new(black_box(bytes.clone())),
|
|
"multipart/form-data; boundary=boundary",
|
|
&directory.0,
|
|
&limits,
|
|
scope,
|
|
)
|
|
.await
|
|
.unwrap();
|
|
let fields = multipart
|
|
.finish()
|
|
.unwrap()
|
|
.decode::<BTreeMap<String, String>>(dever_runtime::wire::decode)
|
|
.unwrap();
|
|
checksum += black_box(fields.len());
|
|
}
|
|
let elapsed = started.elapsed().as_nanos();
|
|
assert_eq!(checksum, count * 1000);
|
|
println!("multipart_{count},{sample},1000,{elapsed},{checksum}");
|
|
}
|
|
}
|
|
})
|
|
.unwrap();
|
|
}
|