// [dependencies]
// serde = "1"
// yaml_serde = "0.10"
fn main() {
const N: usize = 10000;
let y = r#"{"":["#.repeat(N) + &r"]}".repeat(N);
let begin = std::time::Instant::now();
let serde::de::IgnoredAny = yaml_serde::from_str(&y).unwrap();
println!("{:?}", begin.elapsed());
}
At N=10k, cargo run --release takes about 1 second. At N=20k, about 4 seconds. At N=40k, 16 seconds. Each doubling of input size quadruples the runtime. This is O(n²) scaling, which is risky for many use cases because relatively small amounts of untrusted input can tie up large amount of CPU time.
At N=10k,
cargo run --releasetakes about 1 second. At N=20k, about 4 seconds. At N=40k, 16 seconds. Each doubling of input size quadruples the runtime. This is O(n²) scaling, which is risky for many use cases because relatively small amounts of untrusted input can tie up large amount of CPU time.