bench: improve `VerifyNestedIfScript` benchmark precision (make stack clearing untimed)
What changed, and why it matters
This commit only changes a benchmark test file. It refines how the performance of a script verification test is measured so that setup work (clearing the stack) is not counted in the timing. There is no change to the Bitcoin Core software that users run, no change to consensus or validation rules, and no security issue.
No security action needed. This is a benchmark-only change and can be reviewed as normal code quality/test tooling work.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff modifies src/bench/verify_script.cpp, specifically the VerifyNestedIfScript benchmark. It switches from copying the stack inside the timed lambda to clearing the stack in a setup callback and using the same stack directly during the timed run. It also adds bench.unit(“script”), epochIterations(1), and tightens the assertion to check both ret and error == SCRIPT_ERR_OK. The EvalScript call itself remains functionally identical (same script, flags, checker, sig version).
Changed components
src/bench/verify_script.cppInspect captured patch +7 / −6
diff --git a/src/bench/verify_script.cpp b/src/bench/verify_script.cpp
index ac636ce8..af254ae7 100644
--- a/src/bench/verify_script.cpp
+++ b/src/bench/verify_script.cpp
@@ -115,12 +115,13 @@ static void VerifyNestedIfScript(benchmark::Bench& bench)
for (int i = 0; i < 100; ++i) {
script << OP_ENDIF;
}
- bench.run([&] {
- auto stack_copy = stack;
- ScriptError error;
- bool ret = EvalScript(stack_copy, script, 0, BaseSignatureChecker(), SigVersion::BASE, &error);
- assert(ret);
- });
+ bench.unit("script").epochIterations(1)
+ .setup([&] { stack.clear(); })
+ .run([&] {
+ ScriptError error;
+ const bool ret{EvalScript(stack, script, /*flags=*/0, BaseSignatureChecker(), SigVersion::BASE, &error)};
+ assert(ret && error == SCRIPT_ERR_OK);
+ });
}
BENCHMARK(VerifyScriptP2WPKH);
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.