Skip to content

Commit

Permalink
feat(rsjudge-judger): ✅ update benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
Jisu-Woniu committed Jun 10, 2024
1 parent 312b18e commit 1820a95
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 34 deletions.
111 changes: 96 additions & 15 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions crates/rsjudge-judger/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
2 changes: 1 addition & 1 deletion crates/rsjudge-judger/benches/data
Submodule data updated 19 files
+0 −1 100k
+0 −1 100k.trim
+0 −1 10M
+0 −1 10M.trim
+0 −1 10k
+1 −0 16k
+1 −1 16k.trim
+0 −1 1M
+0 −1 1M.trim
+1 −16 1k
+1 −16 1k.trim
+1 −0 256k
+1 −0 256k.trim
+1 −0 4M
+1 −0 4M.trim
+1 −1 64M
+1 −1 64M.trim
+6 −0 gen.sh
+4 −2 strip.sh
46 changes: 30 additions & 16 deletions crates/rsjudge-judger/benches/default_comparer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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);
Expand Down

0 comments on commit 1820a95

Please sign in to comment.