From 19631a6d9212949a363d400cd076fb0d4f5af862 Mon Sep 17 00:00:00 2001 From: TimothyBanks Date: Fri, 10 Jul 2026 16:21:53 -0400 Subject: [PATCH] fix: Add perf tests for escrow create and escrow finish --- src/test/app/Wasm_test.cpp | 62 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/src/test/app/Wasm_test.cpp b/src/test/app/Wasm_test.cpp index 537b8b2330..a564f89850 100644 --- a/src/test/app/Wasm_test.cpp +++ b/src/test/app/Wasm_test.cpp @@ -1544,11 +1544,73 @@ struct Wasm_test : public beast::unit_test::Suite } } + template + void + perf(size_t runs, Functor&& f) + { + using std::chrono::duration_cast; + using std::chrono::steady_clock; + + // Warm up first. + for (auto i = size_t{}; i < 10; ++i) + { + BEAST_EXPECT(f()); + } + + auto totalTime = uint64_t{}; + for (auto i = size_t{}; i < runs; ++i) + { + auto const start = steady_clock::now(); + auto result = f(); + auto const end = steady_clock::now(); + totalTime += duration_cast(end - start).count(); + BEAST_EXPECT(result); + } + log << "Average time for " << runs << " runs: " << (totalTime / runs) << " ns" << std::endl; + } + + void + perfEscrowFinish() + { + testcase("perf escrow finish"); + using namespace test::jtx; + + static constexpr auto kRuns = 1000; + + auto const wasm = hexToBytes(kAllHostFunctionsWasmHex); + + Env env{*this}; + auto hfns = TestHostFunctions{env, 0}; + + perf(kRuns, [&] { + return runEscrowWasm(wasm, hfns, 1'000'000, escrowFunctionName, {}).has_value(); + }); + } + + void + perfEscrowCreate() + { + testcase("perf escrow create"); + using namespace test::jtx; + + static constexpr auto kRuns = 1000; + + auto const wasm = hexToBytes(kAllHostFunctionsWasmHex); + + Env env{*this}; + auto mock = HostFunctions{env.journal}; + + perf(kRuns, [&] { return !preflightEscrowWasm(wasm, mock, escrowFunctionName); }); + } + void run() override { using namespace test::jtx; + perfEscrowFinish(); + perfEscrowCreate(); + testGetDataHelperFunctions(); testWasmLib(); testBadWasm();