Changeset View
Changeset View
Standalone View
Standalone View
src/bench/verify_script.cpp
Show All 10 Lines | |||||
#include <script/script.h> | #include <script/script.h> | ||||
#include <script/script_error.h> | #include <script/script_error.h> | ||||
#include <script/standard.h> | #include <script/standard.h> | ||||
#include <streams.h> | #include <streams.h> | ||||
#include <test/util/transaction_utils.h> | #include <test/util/transaction_utils.h> | ||||
#include <array> | #include <array> | ||||
static void VerifyNestedIfScript(benchmark::State &state) { | static void VerifyNestedIfScript(benchmark::Bench &bench) { | ||||
std::vector<std::vector<uint8_t>> stack; | std::vector<std::vector<uint8_t>> stack; | ||||
CScript script; | CScript script; | ||||
for (int i = 0; i < 100; ++i) { | for (int i = 0; i < 100; ++i) { | ||||
script << OP_1 << OP_IF; | script << OP_1 << OP_IF; | ||||
} | } | ||||
for (int i = 0; i < 1000; ++i) { | for (int i = 0; i < 1000; ++i) { | ||||
script << OP_1; | script << OP_1; | ||||
} | } | ||||
for (int i = 0; i < 100; ++i) { | for (int i = 0; i < 100; ++i) { | ||||
script << OP_ENDIF; | script << OP_ENDIF; | ||||
} | } | ||||
while (state.KeepRunning()) { | bench.run([&] { | ||||
auto stack_copy = stack; | auto stack_copy = stack; | ||||
ScriptExecutionMetrics metrics = {}; | ScriptExecutionMetrics metrics = {}; | ||||
ScriptError error; | ScriptError error; | ||||
bool ret = EvalScript(stack_copy, script, 0, BaseSignatureChecker(), | bool ret = EvalScript(stack_copy, script, 0, BaseSignatureChecker(), | ||||
metrics, &error); | metrics, &error); | ||||
assert(ret); | assert(ret); | ||||
} | }); | ||||
} | } | ||||
BENCHMARK(VerifyNestedIfScript, 100); | BENCHMARK(VerifyNestedIfScript); |