1
mirror of https://github.com/bitcoin/bitcoin synced 2024-07-29 08:48:30 +02:00

Merge #16299: bench: Move generated data to a dedicated translation unit

3d60a03a7c bench: Move generated data to a dedicated translation unit (João Barbosa)

Pull request description:

  With this change multiple benchmarks can use the same data without incurring in a bigger binary.

ACKs for top commit:
  laanwj:
    code review ACK 3d60a03a7c

Tree-SHA512: 8903bb09e4327c88e585a09bc7df1cbdfc18ebdc5d9c86bf3d6d9252a05eaf18b14ecd2bafdacd82f05a659e4b35ecd301c36011c97f7bf89302793165b00fdc
This commit is contained in:
MarcoFalke 2019-07-03 11:12:16 -04:00
commit 91c345eb92
No known key found for this signature in database
GPG Key ID: D2EA4850E7528B25
5 changed files with 44 additions and 15 deletions

View File

@ -20,6 +20,7 @@
<ClCompile Include="..\..\src\bench\checkqueue.cpp" />
<ClCompile Include="..\..\src\bench\coin_selection.cpp" />
<ClCompile Include="..\..\src\bench\crypto_hash.cpp" />
<ClCompile Include="..\..\src\bench\data.cpp" />
<ClCompile Include="..\..\src\bench\examples.cpp" />
<ClCompile Include="..\..\src\bench\lockedpool.cpp" />
<ClCompile Include="..\..\src\bench\mempool_eviction.cpp" />
@ -68,7 +69,7 @@
<ItemGroup>
<RawBenchFile Include="..\..\src\bench\data\*.raw" />
</ItemGroup>
<HeaderFromHexdump RawFilePath="%(RawBenchFile.FullPath)" HeaderFilePath="%(RawBenchFile.FullPath).h" SourceHeader="static unsigned const char %(RawBenchFile.Filename)[] = {" SourceFooter="};" />
<HeaderFromHexdump RawFilePath="%(RawBenchFile.FullPath)" HeaderFilePath="%(RawBenchFile.FullPath).h" SourceHeader="static unsigned const char %(RawBenchFile.Filename)_raw[] = {" SourceFooter="};" />
</Target>
<Import Label="hexdumpTarget" Project="..\msbuild\tasks\hexdump.targets" />
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />

View File

@ -18,6 +18,8 @@ bench_bench_bitcoin_SOURCES = \
bench/block_assemble.cpp \
bench/checkblock.cpp \
bench/checkqueue.cpp \
bench/data.h \
bench/data.cpp \
bench/duplicate_inputs.cpp \
bench/examples.cpp \
bench/rollingbloom.cpp \
@ -76,7 +78,7 @@ CLEAN_BITCOIN_BENCH = bench/*.gcda bench/*.gcno $(GENERATED_BENCH_FILES)
CLEANFILES += $(CLEAN_BITCOIN_BENCH)
bench/checkblock.cpp: bench/data/block413567.raw.h
bench/data.cpp: bench/data/block413567.raw.h
bitcoin_bench: $(BENCH_BINARY)
@ -89,7 +91,7 @@ bitcoin_bench_clean : FORCE
%.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" "$@"

View File

@ -3,41 +3,34 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <bench/bench.h>
#include <bench/data.h>
#include <chainparams.h>
#include <validation.h>
#include <streams.h>
#include <consensus/validation.h>
namespace block_bench {
#include <bench/data/block413567.raw.h>
} // 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
@ -46,7 +39,7 @@ static void DeserializeAndCheckBlockTest(benchmark::State& state)
while (state.KeepRunning()) {
CBlock block; // Note that CBlock caches its checked state, so we need to recreate it here
stream >> block;
bool rewound = stream.Rewind(sizeof(block_bench::block413567));
bool rewound = stream.Rewind(benchmark::data::block413567.size());
assert(rewound);
CValidationState validationState;

14
src/bench/data.cpp Normal file
View File

@ -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 <bench/data.h>
namespace benchmark {
namespace data {
#include <bench/data/block413567.raw.h>
const std::vector<uint8_t> block413567{block413567_raw, block413567_raw + sizeof(block413567_raw) / sizeof(block413567_raw[0])};
} // namespace data
} // namespace benchmark

19
src/bench/data.h Normal file
View File

@ -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 <cstdint>
#include <vector>
namespace benchmark {
namespace data {
extern const std::vector<uint8_t> block413567;
} // namespace data
} // namespace benchmark
#endif // BITCOIN_BENCH_DATA_H