diff --git a/src/Makefile.bench.include b/src/Makefile.bench.include --- a/src/Makefile.bench.include +++ b/src/Makefile.bench.include @@ -19,6 +19,8 @@ bench/cashaddr.cpp \ bench/checkblock.cpp \ bench/checkqueue.cpp \ + bench/data.h \ + bench/data.cpp \ bench/duplicate_inputs.cpp \ bench/examples.cpp \ bench/rollingbloom.cpp \ @@ -73,7 +75,7 @@ CLEANFILES += $(CLEAN_BITCOIN_BENCH) -bench/checkblock.cpp: bench/data/block413567.raw.h +bench/data.cpp: bench/data/block413567.raw.h bitcoin_bench: $(BENCH_BINARY) @@ -86,7 +88,7 @@ %.raw.h: %.raw @$(MKDIR_P) $(@D) @{ \ - 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/CMakeLists.txt b/src/bench/CMakeLists.txt --- a/src/bench/CMakeLists.txt +++ b/src/bench/CMakeLists.txt @@ -44,6 +44,7 @@ checkqueue.cpp crypto_aes.cpp crypto_hash.cpp + data.cpp duplicate_inputs.cpp examples.cpp gcs_filter.cpp diff --git a/src/bench/checkblock.cpp b/src/bench/checkblock.cpp --- a/src/bench/checkblock.cpp +++ b/src/bench/checkblock.cpp @@ -3,6 +3,7 @@ // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include +#include #include #include @@ -10,35 +11,27 @@ #include #include -namespace block_bench { -#include -} // namespace block_bench - // 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::State &state) { - CDataStream stream((const char *)block_bench::block413567, - (const char *)block_bench::block413567 + - sizeof(block_bench::block413567), - SER_NETWORK, PROTOCOL_VERSION); + CDataStream stream(benchmark::data::block413567, SER_NETWORK, + PROTOCOL_VERSION); char a = '\0'; stream.write(&a, 1); // Prevent compaction while (state.KeepRunning()) { CBlock block; stream >> block; - bool rewound = stream.Rewind(sizeof(block_bench::block413567)); + bool rewound = stream.Rewind(benchmark::data::block413567.size()); assert(rewound); } } static void DeserializeAndCheckBlockTest(benchmark::State &state) { - CDataStream stream((const char *)block_bench::block413567, - (const char *)block_bench::block413567 + - sizeof(block_bench::block413567), - SER_NETWORK, PROTOCOL_VERSION); + CDataStream stream(benchmark::data::block413567, SER_NETWORK, + PROTOCOL_VERSION); char a = '\0'; stream.write(&a, 1); // Prevent compaction @@ -50,7 +43,7 @@ // here. CBlock block; stream >> block; - bool rewound = stream.Rewind(sizeof(block_bench::block413567)); + bool rewound = stream.Rewind(benchmark::data::block413567.size()); assert(rewound); CValidationState validationState; diff --git a/src/bench/data.h b/src/bench/data.h new file mode 100644 --- /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 block413567; + +} // namespace data +} // namespace benchmark + +#endif // BITCOIN_BENCH_DATA_H diff --git a/src/bench/data.cpp b/src/bench/data.cpp new file mode 100644 --- /dev/null +++ b/src/bench/data.cpp @@ -0,0 +1,16 @@ +// 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 block413567{ + block413567_raw, + block413567_raw + sizeof(block413567_raw) / sizeof(block413567_raw[0])}; + +} // namespace data +} // namespace benchmark diff --git a/src/bench/data/convert-raw-to-header.py b/src/bench/data/convert-raw-to-header.py --- a/src/bench/data/convert-raw-to-header.py +++ b/src/bench/data/convert-raw-to-header.py @@ -8,7 +8,7 @@ with open(input_file, "rb") as f: contents = f.read() - print("static unsigned const char {}[] = {{".format(test_name)) + print("static unsigned const char {}_raw[] = {{".format(test_name)) print(", ".join(map(lambda x: "0x{:02x}".format(x), contents))) print("};")