build: migrate diff_bench to criterion

Benchmarking is currently nightly-only, so to get `jujutsu` to build on stable, we need to use a stable benchmarking library.
This commit is contained in:
Waleed Khan 2022-02-20 22:21:14 -08:00
parent 261cd1a1c4
commit 75480c2bdc
3 changed files with 30 additions and 11 deletions

10
Cargo.lock generated
View file

@ -251,6 +251,15 @@ dependencies = [
"itertools", "itertools",
] ]
[[package]]
name = "criterion_bencher_compat"
version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cdb92ac87446e7097e0f429c0bb509a1040bfae23bc0320acac30d9fec23d1ed"
dependencies = [
"criterion",
]
[[package]] [[package]]
name = "crossbeam-channel" name = "crossbeam-channel"
version = "0.5.1" version = "0.5.1"
@ -558,6 +567,7 @@ dependencies = [
"clap_complete", "clap_complete",
"config", "config",
"criterion", "criterion",
"criterion_bencher_compat",
"git2", "git2",
"hex", "hex",
"indoc", "indoc",

View file

@ -16,6 +16,10 @@ categories = ["command-line-utilities", "development-tools"]
name = "jj" name = "jj"
path = "src/main.rs" path = "src/main.rs"
[[bench]]
name = "diff_bench"
harness = false
[workspace] [workspace]
members = ["lib"] members = ["lib"]
@ -42,3 +46,5 @@ thiserror = "1.0.30"
[dev-dependencies] [dev-dependencies]
test-case = "1.2.3" test-case = "1.2.3"
regex = "1.5.4" regex = "1.5.4"
criterion = "0.3.5"
criterion_bencher_compat = "0.3.4"

View file

@ -1,9 +1,7 @@
#![feature(test)] use bencher::{benchmark_group, benchmark_main, Bencher};
use criterion_bencher_compat as bencher;
extern crate test;
use jujutsu_lib::diff; use jujutsu_lib::diff;
use test::Bencher;
fn unchanged_lines(count: usize) -> (String, String) { fn unchanged_lines(count: usize) -> (String, String) {
let mut lines = vec![]; let mut lines = vec![];
@ -33,43 +31,36 @@ fn reversed_lines(count: usize) -> (String, String) {
(left_lines.join(""), right_lines.join("")) (left_lines.join(""), right_lines.join(""))
} }
#[bench]
fn bench_diff_1k_unchanged_lines(b: &mut Bencher) { fn bench_diff_1k_unchanged_lines(b: &mut Bencher) {
let (left, right) = unchanged_lines(1000); let (left, right) = unchanged_lines(1000);
b.iter(|| diff::diff(left.as_bytes(), right.as_bytes())); b.iter(|| diff::diff(left.as_bytes(), right.as_bytes()));
} }
#[bench]
fn bench_diff_10k_unchanged_lines(b: &mut Bencher) { fn bench_diff_10k_unchanged_lines(b: &mut Bencher) {
let (left, right) = unchanged_lines(10000); let (left, right) = unchanged_lines(10000);
b.iter(|| diff::diff(left.as_bytes(), right.as_bytes())); b.iter(|| diff::diff(left.as_bytes(), right.as_bytes()));
} }
#[bench]
fn bench_diff_1k_modified_lines(b: &mut Bencher) { fn bench_diff_1k_modified_lines(b: &mut Bencher) {
let (left, right) = modified_lines(1000); let (left, right) = modified_lines(1000);
b.iter(|| diff::diff(left.as_bytes(), right.as_bytes())); b.iter(|| diff::diff(left.as_bytes(), right.as_bytes()));
} }
#[bench]
fn bench_diff_10k_modified_lines(b: &mut Bencher) { fn bench_diff_10k_modified_lines(b: &mut Bencher) {
let (left, right) = modified_lines(10000); let (left, right) = modified_lines(10000);
b.iter(|| diff::diff(left.as_bytes(), right.as_bytes())); b.iter(|| diff::diff(left.as_bytes(), right.as_bytes()));
} }
#[bench]
fn bench_diff_1k_lines_reversed(b: &mut Bencher) { fn bench_diff_1k_lines_reversed(b: &mut Bencher) {
let (left, right) = reversed_lines(1000); let (left, right) = reversed_lines(1000);
b.iter(|| diff::diff(left.as_bytes(), right.as_bytes())); b.iter(|| diff::diff(left.as_bytes(), right.as_bytes()));
} }
#[bench]
fn bench_diff_10k_lines_reversed(b: &mut Bencher) { fn bench_diff_10k_lines_reversed(b: &mut Bencher) {
let (left, right) = reversed_lines(10000); let (left, right) = reversed_lines(10000);
b.iter(|| diff::diff(left.as_bytes(), right.as_bytes())); b.iter(|| diff::diff(left.as_bytes(), right.as_bytes()));
} }
#[bench]
fn bench_diff_git_git_read_tree_c(b: &mut Bencher) { fn bench_diff_git_git_read_tree_c(b: &mut Bencher) {
b.iter(|| { b.iter(|| {
diff::diff( diff::diff(
@ -214,3 +205,15 @@ int main(int argc, char **argv)
) )
}); });
} }
benchmark_group!(
benches,
bench_diff_1k_unchanged_lines,
bench_diff_10k_unchanged_lines,
bench_diff_1k_modified_lines,
bench_diff_10k_modified_lines,
bench_diff_1k_lines_reversed,
bench_diff_10k_lines_reversed,
bench_diff_git_git_read_tree_c,
);
benchmark_main!(benches);