This repository has been archived by the owner on Sep 24, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Also add regression test
- Loading branch information
Showing
2 changed files
with
73 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
use std::time::{Duration, Instant}; | ||
use toml::Value; | ||
|
||
const TOLERANCE: f64 = 2.0; | ||
|
||
fn measure_time(entries: usize, f: impl Fn(usize) -> String) -> Duration { | ||
let start = Instant::now(); | ||
let mut s = String::new(); | ||
for i in 0..entries { | ||
s += &f(i); | ||
s += "entry = 42\n" | ||
} | ||
s.parse::<Value>().unwrap(); | ||
Instant::now() - start | ||
} | ||
|
||
#[test] | ||
fn linear_increase_map() { | ||
let time_1 = measure_time(100, |i| format!("[header_no_{}]\n", i)); | ||
let time_4 = measure_time(400, |i| format!("[header_no_{}]\n", i)); | ||
dbg!(time_1, time_4); | ||
// Now ensure that the deserialization time has increased linearly | ||
// (within a tolerance interval) instead of, say, quadratically | ||
assert!(time_4 > time_1.mul_f64(4.0 - TOLERANCE)); | ||
assert!(time_4 < time_1.mul_f64(4.0 + TOLERANCE)); | ||
} | ||
|
||
#[test] | ||
fn linear_increase_array() { | ||
let time_1 = measure_time(100, |i| format!("[[header_no_{}]]\n", i)); | ||
let time_4 = measure_time(400, |i| format!("[[header_no_{}]]\n", i)); | ||
dbg!(time_1, time_4); | ||
// Now ensure that the deserialization time has increased linearly | ||
// (within a tolerance interval) instead of, say, quadratically | ||
assert!(time_4 > time_1.mul_f64(4.0 - TOLERANCE)); | ||
assert!(time_4 < time_1.mul_f64(4.0 + TOLERANCE)); | ||
} |