feat: Add some performance tests for escrow wasm functions

This commit is contained in:
TimothyBanks
2026-07-22 15:57:08 -04:00
parent d1d3e3c72e
commit fca18f59cd
3 changed files with 16 additions and 7 deletions

View File

@@ -132,10 +132,13 @@ runEscrowWasm(
auto const ret =
vm.run(wasmCode, hfs, gasLimit, funcName, params, createWasmImport(hfs), hfs.getJournal());
// microseconds is intentional. The resolution of the StatsD is milliseconds,
// but this runs too fast for that.
hfs.executionTimeEvent("runEscrowWasm")
.notify(
std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::steady_clock::now() - start));
std::chrono::milliseconds{std::chrono::duration_cast<std::chrono::microseconds>(
std::chrono::steady_clock::now() - start)
.count()});
if (!ret)
{
@@ -167,10 +170,13 @@ preflightEscrowWasm(
auto const ret =
vm.check(wasmCode, hfs, funcName, params, createWasmImport(hfs), hfs.getJournal());
// microseconds is intentional. The resolution of the StatsD is milliseconds,
// but this runs too fast for that.
hfs.executionTimeEvent("preflightEscrowWasm")
.notify(
std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::steady_clock::now() - start));
std::chrono::milliseconds{std::chrono::duration_cast<std::chrono::microseconds>(
std::chrono::steady_clock::now() - start)
.count()});
return ret;
}

View File

@@ -35,12 +35,13 @@ struct RecordingEventImpl : public beast::insight::EventImpl
value_type min{value_type::max()};
value_type max{value_type::min()};
std::vector<value_type> samples;
bool printOnDestruction{};
~RecordingEventImpl() override
{
if (count > 0)
if (printOnDestruction && count > 0)
{
std::cout << "Mean (ms): " << meanMs() << "\n";
std::cout << "Mean (us): " << meanUs() << "\n";
}
}
@@ -56,7 +57,7 @@ struct RecordingEventImpl : public beast::insight::EventImpl
}
[[nodiscard]] double
meanMs() const
meanUs() const
{
return count != 0 ? static_cast<double>(total.count()) / static_cast<double>(count) : 0.0;
}

View File

@@ -1568,6 +1568,7 @@ struct Wasm_test : public beast::unit_test::Suite
Env env{*this};
auto hfns = TestHostFunctions{env, 0};
hfns.execTimeEvent->printOnDestruction = true;
perf(hfns, kRuns, [&] {
return runEscrowWasm(wasm, hfns, 1'000'000, escrowFunctionName, {}).has_value();
@@ -1586,6 +1587,7 @@ struct Wasm_test : public beast::unit_test::Suite
Env env{*this};
auto hfns = TestHostFunctions{env, 0};
hfns.execTimeEvent->printOnDestruction = true;
perf(hfns, kRuns, [&] { return !preflightEscrowWasm(wasm, hfns, escrowFunctionName); });
}