Skip to content

Commit

Permalink
chore(tests): etalon benchmarking test for network team convenience (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
raftedproc authored Nov 13, 2023
1 parent a8965e0 commit 973e8ae
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
4 changes: 4 additions & 0 deletions air/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,7 @@ harness = false
[[bench]]
name = "data_long_benchmark"
harness = false

[[bench]]
name = "nox_tc2_benchmark"
harness = false
40 changes: 40 additions & 0 deletions air/benches/nox_tc2_benchmark.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
use air_test_utils::prelude::*;

use criterion::criterion_group;
use criterion::criterion_main;
use criterion::Criterion;

use std::cell::RefCell;
use std::time::Duration;

thread_local!(static VM: RefCell<TestRunner<ReleaseWasmAirRunner>> = RefCell::new(
create_custom_avm(unit_call_service(), "test_peer_id"))
);
thread_local!(static SCRIPT: String = String::from(
r#"
(seq
(ap "123" $stream)
(canon "test_peer_id" $stream #stream-canon)
)
"#,
)
);

fn nox_tc2_benchmark() -> Result<RawAVMOutcome, String> {
let run_parameters = TestRunParameters::new("test_peer_id", 0, 1, "");
VM.with(|vm| SCRIPT.with(|script| vm.borrow_mut().call(script, "", "", run_parameters)))
}

fn criterion_benchmark(c: &mut Criterion) {
c.bench_function("nox_tc2_benchmark", move |b: &mut criterion::Bencher<'_>| {
b.iter(nox_tc2_benchmark)
});
}

criterion_group! {
name = benches;
// This can be any expression that returns a `Criterion` object.
config = Criterion::default().measurement_time(Duration::from_secs(10));
targets = criterion_benchmark
}
criterion_main!(benches);

0 comments on commit 973e8ae

Please sign in to comment.