Skip to content

Commit

Permalink
test(bench): fix bench runner
Browse files Browse the repository at this point in the history
  • Loading branch information
SARDONYX-sard committed Nov 16, 2023
1 parent 71b5f0d commit 9ee01ec
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
1 change: 1 addition & 0 deletions dar2oar_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ tokio = { version = "1.33.0", features = [
"io-util",
"macros",
"rt",
"rt-multi-thread",
] } # Async Executor
tokio-stream = "0.1.14" # Async next() method
tracing = "0.1.40" # Logger
Expand Down
11 changes: 7 additions & 4 deletions dar2oar_core/benches/convert_n_thread.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use criterion::async_executor::FuturesExecutor;
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use dar2oar_core::fs::converter::{parallel, sequential};
use dar2oar_core::{read_mapping_table, Closure, ConvertOptions};
Expand All @@ -12,10 +11,13 @@ const TABLE_PATH: &str = "../test/settings/UnderDog Animations_v1.9.6_mapping_ta

fn criterion_benchmark(c: &mut Criterion) {
let mut group = c.benchmark_group("dar2oar sequential vs parallel");
group.warm_up_time(Duration::from_secs(70)).sample_size(10);
group
.measurement_time(Duration::from_secs(23))
.sample_size(10);

group.bench_function("dar2oar multi thread", |b| {
b.to_async(FuturesExecutor).iter(|| async {
let rt = tokio::runtime::Runtime::new().unwrap();
b.to_async(rt).iter(|| async {
if std::path::Path::new(REMOVE_TARGET).exists() {
fs::remove_dir_all(REMOVE_TARGET).await.unwrap();
}
Expand All @@ -34,7 +36,8 @@ fn criterion_benchmark(c: &mut Criterion) {
});

group.bench_function("dar2oar single thread", |b| {
b.to_async(FuturesExecutor).iter(|| async {
let rt = tokio::runtime::Runtime::new().unwrap();
b.to_async(&rt).iter(|| async {
if std::path::Path::new(REMOVE_TARGET).exists() {
fs::remove_dir_all(REMOVE_TARGET).await.unwrap();
}
Expand Down
15 changes: 15 additions & 0 deletions dar2oar_core/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,18 @@ async fn main() -> Result<()> {
Ok(())
}
```

## How to run bench

Requirements

- test mod: "../test/data/UNDERDOG Animations"
- mapping_table: "../test/settings/UnderDog Animations_v1.9.6_mapping_table.txt"

```shell
cargo bench
# dar2oar sequential vs parallel/dar2oar multi thread
# time: [1.5880 s 1.6398 s 1.6992 s]
# dar2oar sequential vs parallel/dar2oar single thread
# time: [1.9711 s 2.0215 s 2.0908 s]
```

0 comments on commit 9ee01ec

Please sign in to comment.