From 4673cfd79788c74c5bd6bcabe564c2dfcbd7c553 Mon Sep 17 00:00:00 2001 From: est31 Date: Tue, 29 Oct 2019 15:10:15 +0100 Subject: Replace the test added by #349 with a bench (#351) CI environments can be noisy and while the test worked great locally on my machine, it didn't on the CI environment. This replaces the test with a (manually tracked) benchmark. As per https://github.com/alexcrichton/toml-rs/pull/349#issuecomment-546998173 --- test-suite/benches/linear.rs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 test-suite/benches/linear.rs (limited to 'test-suite/benches') diff --git a/test-suite/benches/linear.rs b/test-suite/benches/linear.rs new file mode 100644 index 0000000..1553595 --- /dev/null +++ b/test-suite/benches/linear.rs @@ -0,0 +1,35 @@ +// Regressoion test for https://github.com/alexcrichton/toml-rs/issues/342 + +use bencher::{benchmark_group, benchmark_main, black_box, Bencher}; +use toml::Value; + +fn parse(bench: &mut Bencher, entries: usize, f: impl Fn(usize) -> String) { + let mut s = String::new(); + for i in 0..entries { + s += &f(i); + s += "entry = 42\n" + } + let s = black_box(s); + bench.iter(|| { + black_box(s.parse::().unwrap()); + }) +} + +fn map_10(bench: &mut Bencher) { + parse(bench, 10, |i| format!("[header_no_{}]\n", i)) +} + +fn map_100(bench: &mut Bencher) { + parse(bench, 100, |i| format!("[header_no_{}]\n", i)) +} + +fn array_10(bench: &mut Bencher) { + parse(bench, 10, |_i| "[[header]]\n".to_owned()) +} + +fn array_100(bench: &mut Bencher) { + parse(bench, 100, |_i| "[[header]]\n".to_owned()) +} + +benchmark_group!(benches, map_10, map_100, array_10, array_100); +benchmark_main!(benches); -- cgit v1.2.3