From 1820a95ba10ba7d7cf90356fc2f7f788ece255da Mon Sep 17 00:00:00 2001 From: Jisu-Woniu <31986081+Jisu-Woniu@users.noreply.github.com> Date: Mon, 10 Jun 2024 16:30:02 +0800 Subject: [PATCH] =?UTF-8?q?feat(rsjudge-judger):=20=E2=9C=85=20update=20be?= =?UTF-8?q?nchmark?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.lock | 111 +++++++++++++++--- crates/rsjudge-judger/Cargo.toml | 3 +- crates/rsjudge-judger/benches/data | 2 +- .../benches/default_comparer.rs | 46 +++++--- 4 files changed, 128 insertions(+), 34 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7eacc6b..4d63c3c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -69,9 +69,9 @@ dependencies = [ [[package]] name = "anes" -version = "0.2.0" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "735d4f398ca57cfa2880225c2bf81c3b9af3be5bb22e44ae70118dad38713e84" +checksum = "4b46cbb362ab8752921c97e041f5e366ee6297bd428a31275b9fcf1e380f7299" [[package]] name = "anstream" @@ -300,12 +300,6 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" -[[package]] -name = "bpaf" -version = "0.9.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3280efcf6d66bc77c2cf9b67dc8acee47a217d9be67dd590b3230dffe663724d" - [[package]] name = "bumpalo" version = "3.16.0" @@ -473,24 +467,43 @@ dependencies = [ ] [[package]] -name = "criterion2" -version = "0.10.0" +name = "criterion" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f22174bed309c964c1720148dfe793f285cc02fd8b13c91205d485f73468d94d" +checksum = "f2b12d017a929603d80db1831cd3a24082f8137ce19c69e6447f54f5fc8d692f" dependencies = [ "anes", - "bpaf", "cast", "ciborium", + "clap", + "criterion-plot", + "futures", + "is-terminal", + "itertools 0.10.5", "num-traits", + "once_cell", "oorandom", + "plotters", "rayon", + "regex", "serde", + "serde_derive", "serde_json", + "tinytemplate", "tokio", "walkdir", ] +[[package]] +name = "criterion-plot" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b50826342786a51a89e2da3a28f1c32b06e387201bc2d19791f622c673706b1" +dependencies = [ + "cast", + "itertools 0.10.5", +] + [[package]] name = "crossbeam-deque" version = "0.8.5" @@ -1053,12 +1066,32 @@ dependencies = [ "serde", ] +[[package]] +name = "is-terminal" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f23ff5ef2b80d608d61efee834934d862cd92461afc0560dedf493e4c033738b" +dependencies = [ + "hermit-abi", + "libc", + "windows-sys 0.52.0", +] + [[package]] name = "is_terminal_polyfill" version = "1.70.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f8478577c03552c21db0e2724ffb8986a5ce7af88107e6be5d2ee6e158c12800" +[[package]] +name = "itertools" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" +dependencies = [ + "either", +] + [[package]] name = "itertools" version = "0.12.1" @@ -1395,6 +1428,34 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" +[[package]] +name = "plotters" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a15b6eccb8484002195a3e44fe65a4ce8e93a625797a063735536fd59cb01cf3" +dependencies = [ + "num-traits", + "plotters-backend", + "plotters-svg", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "plotters-backend" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "414cec62c6634ae900ea1c56128dfe87cf63e7caece0852ec76aba307cebadb7" + +[[package]] +name = "plotters-svg" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81b30686a7d9c3e010b84284bdd26a29f2138574f52f5eb6f794fc0ad924e705" +dependencies = [ + "plotters-backend", +] + [[package]] name = "ppv-lite86" version = "0.2.17" @@ -1488,7 +1549,7 @@ checksum = "22505a5c94da8e3b7c2996394d1c933236c4d743e81a410bcca4e6989fc066a4" dependencies = [ "bytes", "heck", - "itertools", + "itertools 0.12.1", "log", "multimap", "once_cell", @@ -1508,7 +1569,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "81bddcdb20abf9501610992b6759a4c888aef7d1a7247ef75e2404275ac24af1" dependencies = [ "anyhow", - "itertools", + "itertools 0.12.1", "proc-macro2", "quote", "syn 2.0.66", @@ -1685,7 +1746,7 @@ name = "rsjudge-judger" version = "0.1.0" dependencies = [ "async-trait", - "criterion2", + "criterion", "futures", "rsjudge-utils", "tempfile", @@ -2021,6 +2082,16 @@ dependencies = [ "syn 2.0.66", ] +[[package]] +name = "tinytemplate" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be4d6b5f19ff7664e8c98d03e2139cb510db9b0a60b55f8e8709b689d939b6bc" +dependencies = [ + "serde", + "serde_json", +] + [[package]] name = "tokio" version = "1.38.0" @@ -2361,6 +2432,16 @@ version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" +[[package]] +name = "web-sys" +version = "0.3.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77afa9a11836342370f4817622a2f0f418b134426d91a82dfb48f532d2ec13ef" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + [[package]] name = "winapi" version = "0.3.9" diff --git a/crates/rsjudge-judger/Cargo.toml b/crates/rsjudge-judger/Cargo.toml index c49b3f2..51240ab 100644 --- a/crates/rsjudge-judger/Cargo.toml +++ b/crates/rsjudge-judger/Cargo.toml @@ -20,7 +20,6 @@ rsjudge-utils.workspace = true tokio = { version = "1.38.0", features = ["io-util", "fs", "macros"] } [dev-dependencies] -# criterion = { version = "0.5.1", features = ["async_tokio", "html_reports"] } -criterion2 = { version = "0.10.0", features = ["async_tokio"] } +criterion = { version = "0.5.1", features = ["async_tokio", "html_reports"] } tempfile = "3.10.1" tokio = { version = "1.38.0", features = ["rt-multi-thread", "full"] } diff --git a/crates/rsjudge-judger/benches/data b/crates/rsjudge-judger/benches/data index 087a077..1428e7a 160000 --- a/crates/rsjudge-judger/benches/data +++ b/crates/rsjudge-judger/benches/data @@ -1 +1 @@ -Subproject commit 087a077cc3bb06e149a3f599351230059c25936d +Subproject commit 1428e7ac8dc6ee7cc85f134449be700521c58565 diff --git a/crates/rsjudge-judger/benches/default_comparer.rs b/crates/rsjudge-judger/benches/default_comparer.rs index 61654db..d2deeca 100644 --- a/crates/rsjudge-judger/benches/default_comparer.rs +++ b/crates/rsjudge-judger/benches/default_comparer.rs @@ -8,9 +8,8 @@ use tokio::{fs::File, runtime::Runtime}; fn bench(c: &mut Criterion) { let data_dir = Path::new("./benches/data"); - let data_file = data_dir.join("100M"); - let data_file_trimmed = data_dir.join("100M.trim"); - const MB: u64 = 1024 * 1024; + const KILO: u64 = 1024; + const MEGA: u64 = 1024 * 1024; const COMPARERS: &[(DefaultComparer, &str)] = &[ (DefaultComparer::common(), "common"), (DefaultComparer::exact_match(), "exact-match"), @@ -22,22 +21,37 @@ fn bench(c: &mut Criterion) { let mut group = c.benchmark_group("DefaultComparer"); group.sampling_mode(SamplingMode::Flat); + for (size_str, bytes) in [ + ("1k", KILO), + ("16k", 16 * KILO), + ("256k", 256 * KILO), + ("4M", 4 * MEGA), + ("64M", 64 * MEGA), + ] { + let data_file = data_dir.join(size_str); - for (comparer, id) in COMPARERS { - group.throughput(Throughput::Bytes(100 * MB)); - group.bench_with_input(BenchmarkId::from_parameter(id), comparer, |b, comparer| { - b.to_async(Runtime::new().unwrap()).iter(|| async { - let result = black_box(comparer) - .compare( - File::open(black_box(&data_file)).await?, - File::open(black_box(&data_file_trimmed)).await?, - ) - .await?; + let data_file_trimmed = data_dir.join(format!("{}.trim", size_str)); + for (comparer, id) in COMPARERS { + group.throughput(Throughput::Bytes(bytes)); + group.bench_with_input( + BenchmarkId::new(*id, size_str), + &(data_file.as_path(), data_file_trimmed.as_path()), + |b, (data_file, data_file_trimmed)| { + b.to_async(Runtime::new().unwrap()).iter(|| async { + let result = black_box(comparer) + .compare( + File::open(black_box(data_file)).await?, + File::open(black_box(data_file_trimmed)).await?, + ) + .await?; - Ok::<_, io::Error>(result) - }); - }); + Ok::<_, io::Error>(result) + }); + }, + ); + } } + group.finish(); } criterion_group!(benches, bench);