From 973e8aeea5b56034bd60b0c864f9f6a49b9919a9 Mon Sep 17 00:00:00 2001 From: raftedproc <71657594+raftedproc@users.noreply.github.com> Date: Mon, 13 Nov 2023 21:22:54 +0300 Subject: [PATCH] chore(tests): etalon benchmarking test for network team convenience (#754) --- air/Cargo.toml | 4 ++++ air/benches/nox_tc2_benchmark.rs | 40 ++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 air/benches/nox_tc2_benchmark.rs diff --git a/air/Cargo.toml b/air/Cargo.toml index 46790083f2..7918cbde76 100644 --- a/air/Cargo.toml +++ b/air/Cargo.toml @@ -85,3 +85,7 @@ harness = false [[bench]] name = "data_long_benchmark" harness = false + +[[bench]] +name = "nox_tc2_benchmark" +harness = false \ No newline at end of file diff --git a/air/benches/nox_tc2_benchmark.rs b/air/benches/nox_tc2_benchmark.rs new file mode 100644 index 0000000000..598bdfbada --- /dev/null +++ b/air/benches/nox_tc2_benchmark.rs @@ -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> = 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 { + 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);