Skip to content
This repository has been archived by the owner on Sep 24, 2022. It is now read-only.

Replace the test added by #349 with a bench #351

Merged
merged 1 commit into from Oct 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Expand Up @@ -15,6 +15,7 @@ jobs:
- run: cargo test
- run: cargo test --features preserve_order
- run: cargo test --manifest-path test-suite/Cargo.toml
- run: cargo bench

rustfmt:
name: Rustfmt
Expand Down
5 changes: 5 additions & 0 deletions test-suite/Cargo.toml
Expand Up @@ -5,7 +5,12 @@ authors = ["Alex Crichton <alex@alexcrichton.com>"]
publish = false
edition = "2018"

[[bench]]
name = "linear"
harness = false

[dev-dependencies]
bencher = "0.1"
toml = { path = ".." }
serde = { version = "1.0", features = ["derive"] }
serde_derive = "1.0"
Expand Down
35 changes: 35 additions & 0 deletions 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::<Value>().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);
37 changes: 0 additions & 37 deletions test-suite/tests/linear.rs

This file was deleted.