Skip to content

Commit 1820a95

Browse files
committed
feat(rsjudge-judger): ✅ update benchmark
1 parent 312b18e commit 1820a95

File tree

4 files changed

+128
-34
lines changed

4 files changed

+128
-34
lines changed

Cargo.lock

Lines changed: 96 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/rsjudge-judger/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ rsjudge-utils.workspace = true
2020
tokio = { version = "1.38.0", features = ["io-util", "fs", "macros"] }
2121

2222
[dev-dependencies]
23-
# criterion = { version = "0.5.1", features = ["async_tokio", "html_reports"] }
24-
criterion2 = { version = "0.10.0", features = ["async_tokio"] }
23+
criterion = { version = "0.5.1", features = ["async_tokio", "html_reports"] }
2524
tempfile = "3.10.1"
2625
tokio = { version = "1.38.0", features = ["rt-multi-thread", "full"] }

crates/rsjudge-judger/benches/default_comparer.rs

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ use tokio::{fs::File, runtime::Runtime};
88

99
fn bench(c: &mut Criterion) {
1010
let data_dir = Path::new("./benches/data");
11-
let data_file = data_dir.join("100M");
12-
let data_file_trimmed = data_dir.join("100M.trim");
13-
const MB: u64 = 1024 * 1024;
11+
const KILO: u64 = 1024;
12+
const MEGA: u64 = 1024 * 1024;
1413
const COMPARERS: &[(DefaultComparer, &str)] = &[
1514
(DefaultComparer::common(), "common"),
1615
(DefaultComparer::exact_match(), "exact-match"),
@@ -22,22 +21,37 @@ fn bench(c: &mut Criterion) {
2221

2322
let mut group = c.benchmark_group("DefaultComparer");
2423
group.sampling_mode(SamplingMode::Flat);
24+
for (size_str, bytes) in [
25+
("1k", KILO),
26+
("16k", 16 * KILO),
27+
("256k", 256 * KILO),
28+
("4M", 4 * MEGA),
29+
("64M", 64 * MEGA),
30+
] {
31+
let data_file = data_dir.join(size_str);
2532

26-
for (comparer, id) in COMPARERS {
27-
group.throughput(Throughput::Bytes(100 * MB));
28-
group.bench_with_input(BenchmarkId::from_parameter(id), comparer, |b, comparer| {
29-
b.to_async(Runtime::new().unwrap()).iter(|| async {
30-
let result = black_box(comparer)
31-
.compare(
32-
File::open(black_box(&data_file)).await?,
33-
File::open(black_box(&data_file_trimmed)).await?,
34-
)
35-
.await?;
33+
let data_file_trimmed = data_dir.join(format!("{}.trim", size_str));
34+
for (comparer, id) in COMPARERS {
35+
group.throughput(Throughput::Bytes(bytes));
36+
group.bench_with_input(
37+
BenchmarkId::new(*id, size_str),
38+
&(data_file.as_path(), data_file_trimmed.as_path()),
39+
|b, (data_file, data_file_trimmed)| {
40+
b.to_async(Runtime::new().unwrap()).iter(|| async {
41+
let result = black_box(comparer)
42+
.compare(
43+
File::open(black_box(data_file)).await?,
44+
File::open(black_box(data_file_trimmed)).await?,
45+
)
46+
.await?;
3647

37-
Ok::<_, io::Error>(result)
38-
});
39-
});
48+
Ok::<_, io::Error>(result)
49+
});
50+
},
51+
);
52+
}
4053
}
54+
group.finish();
4155
}
4256

4357
criterion_group!(benches, bench);

0 commit comments

Comments
 (0)