diff --git a/src/Makefile.bench.include b/src/Makefile.bench.include index ffd97844ee..653da08f39 100644 --- a/src/Makefile.bench.include +++ b/src/Makefile.bench.include @@ -21,6 +21,8 @@ bench_bench_dash_SOURCES = \ bench/bls_dkg.cpp \ bench/checkblock.cpp \ bench/checkqueue.cpp \ + bench/data.h \ + bench/data.cpp \ bench/duplicate_inputs.cpp \ bench/ecdsa.cpp \ bench/examples.cpp \ @@ -83,7 +85,7 @@ CLEAN_BITCOIN_BENCH = bench/*.gcda bench/*.gcno $(GENERATED_BENCH_FILES) CLEANFILES += $(CLEAN_BITCOIN_BENCH) -bench/checkblock.cpp: bench/data/block813851.raw.h +bench/data.cpp: bench/data/block813851.raw.h bitcoin_bench: $(BENCH_BINARY) @@ -97,7 +99,7 @@ bench/data/%.raw.h: bench/data/%.raw @$(MKDIR_P) $(@D) @{ \ echo "namespace raw_bench{" && \ - echo "static unsigned const char $(*F)[] = {" && \ + echo "static unsigned const char $(*F)_raw[] = {" && \ $(HEXDUMP) -v -e '8/1 "0x%02x, "' -e '"\n"' $< | $(SED) -e 's/0x ,//g' && \ echo "};};"; \ } > "$@.new" && mv -f "$@.new" "$@" diff --git a/src/bench/checkblock.cpp b/src/bench/checkblock.cpp index f91ec7080b..0916fdd68f 100644 --- a/src/bench/checkblock.cpp +++ b/src/bench/checkblock.cpp @@ -3,39 +3,34 @@ // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include +#include #include #include #include #include -#include - // These are the two major time-sinks which happen after we have fully received // a block off the wire, but before we can relay the block on to peers using // compact block relay. static void DeserializeBlockTest(benchmark::Bench& bench) { - CDataStream stream((const char*)raw_bench::block813851, - (const char*)raw_bench::block813851+sizeof(raw_bench::block813851), - SER_NETWORK, PROTOCOL_VERSION); + CDataStream stream(benchmark::data::block813851, SER_NETWORK, PROTOCOL_VERSION); char a = '\0'; stream.write(&a, 1); // Prevent compaction bench.unit("block").run([&] { CBlock block; stream >> block; - bool rewound = stream.Rewind(sizeof(raw_bench::block813851)); + bool rewound = stream.Rewind(benchmark::data::block813851.size()); assert(rewound); }); } static void DeserializeAndCheckBlockTest(benchmark::Bench& bench) { - CDataStream stream((const char*)raw_bench::block813851, - (const char*)raw_bench::block813851+sizeof(raw_bench::block813851), - SER_NETWORK, PROTOCOL_VERSION); + CDataStream stream(benchmark::data::block813851, SER_NETWORK, PROTOCOL_VERSION); char a = '\0'; stream.write(&a, 1); // Prevent compaction @@ -44,7 +39,7 @@ static void DeserializeAndCheckBlockTest(benchmark::Bench& bench) bench.unit("block").run([&] { CBlock block; // Note that CBlock caches its checked state, so we need to recreate it here stream >> block; - bool rewound = stream.Rewind(sizeof(raw_bench::block813851)); + bool rewound = stream.Rewind(benchmark::data::block813851.size()); assert(rewound); CValidationState validationState; diff --git a/src/bench/data.cpp b/src/bench/data.cpp new file mode 100644 index 0000000000..16f1169fd2 --- /dev/null +++ b/src/bench/data.cpp @@ -0,0 +1,14 @@ +// Copyright (c) 2019 The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include + +namespace benchmark { +namespace data { + +#include +const std::vector block813851{raw_bench::block813851_raw, raw_bench::block813851_raw + sizeof(raw_bench::block813851_raw) / sizeof(raw_bench::block813851_raw[0])}; + +} // namespace data +} // namespace benchmark diff --git a/src/bench/data.h b/src/bench/data.h new file mode 100644 index 0000000000..bd99a3e53b --- /dev/null +++ b/src/bench/data.h @@ -0,0 +1,19 @@ +// Copyright (c) 2019 The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#ifndef BITCOIN_BENCH_DATA_H +#define BITCOIN_BENCH_DATA_H + +#include +#include + +namespace benchmark { +namespace data { + +extern const std::vector block813851; + +} // namespace data +} // namespace benchmark + +#endif // BITCOIN_BENCH_DATA_H