Skip to content

Commit 91c345e

Browse files
author
MarcoFalke
committed
Merge bitcoin#16299: bench: Move generated data to a dedicated translation unit
3d60a03 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 3d60a03 Tree-SHA512: 8903bb09e4327c88e585a09bc7df1cbdfc18ebdc5d9c86bf3d6d9252a05eaf18b14ecd2bafdacd82f05a659e4b35ecd301c36011c97f7bf89302793165b00fdc
2 parents 11de669 + 3d60a03 commit 91c345e

File tree

5 files changed

+44
-15
lines changed

5 files changed

+44
-15
lines changed

build_msvc/bench_bitcoin/bench_bitcoin.vcxproj

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
<ClCompile Include="..\..\src\bench\checkqueue.cpp" />
2121
<ClCompile Include="..\..\src\bench\coin_selection.cpp" />
2222
<ClCompile Include="..\..\src\bench\crypto_hash.cpp" />
23+
<ClCompile Include="..\..\src\bench\data.cpp" />
2324
<ClCompile Include="..\..\src\bench\examples.cpp" />
2425
<ClCompile Include="..\..\src\bench\lockedpool.cpp" />
2526
<ClCompile Include="..\..\src\bench\mempool_eviction.cpp" />
@@ -68,7 +69,7 @@
6869
<ItemGroup>
6970
<RawBenchFile Include="..\..\src\bench\data\*.raw" />
7071
</ItemGroup>
71-
<HeaderFromHexdump RawFilePath="%(RawBenchFile.FullPath)" HeaderFilePath="%(RawBenchFile.FullPath).h" SourceHeader="static unsigned const char %(RawBenchFile.Filename)[] = {" SourceFooter="};" />
72+
<HeaderFromHexdump RawFilePath="%(RawBenchFile.FullPath)" HeaderFilePath="%(RawBenchFile.FullPath).h" SourceHeader="static unsigned const char %(RawBenchFile.Filename)_raw[] = {" SourceFooter="};" />
7273
</Target>
7374
<Import Label="hexdumpTarget" Project="..\msbuild\tasks\hexdump.targets" />
7475
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />

src/Makefile.bench.include

+4-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ bench_bench_bitcoin_SOURCES = \
1818
bench/block_assemble.cpp \
1919
bench/checkblock.cpp \
2020
bench/checkqueue.cpp \
21+
bench/data.h \
22+
bench/data.cpp \
2123
bench/duplicate_inputs.cpp \
2224
bench/examples.cpp \
2325
bench/rollingbloom.cpp \
@@ -76,7 +78,7 @@ CLEAN_BITCOIN_BENCH = bench/*.gcda bench/*.gcno $(GENERATED_BENCH_FILES)
7678

7779
CLEANFILES += $(CLEAN_BITCOIN_BENCH)
7880

79-
bench/checkblock.cpp: bench/data/block413567.raw.h
81+
bench/data.cpp: bench/data/block413567.raw.h
8082

8183
bitcoin_bench: $(BENCH_BINARY)
8284

@@ -89,7 +91,7 @@ bitcoin_bench_clean : FORCE
8991
%.raw.h: %.raw
9092
@$(MKDIR_P) $(@D)
9193
@{ \
92-
echo "static unsigned const char $(*F)[] = {" && \
94+
echo "static unsigned const char $(*F)_raw[] = {" && \
9395
$(HEXDUMP) -v -e '8/1 "0x%02x, "' -e '"\n"' $< | $(SED) -e 's/0x ,//g' && \
9496
echo "};"; \
9597
} > "[email protected]" && mv -f "[email protected]" "$@"

src/bench/checkblock.cpp

+5-12
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,34 @@
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

55
#include <bench/bench.h>
6+
#include <bench/data.h>
67

78
#include <chainparams.h>
89
#include <validation.h>
910
#include <streams.h>
1011
#include <consensus/validation.h>
1112

12-
namespace block_bench {
13-
#include <bench/data/block413567.raw.h>
14-
} // namespace block_bench
15-
1613
// These are the two major time-sinks which happen after we have fully received
1714
// a block off the wire, but before we can relay the block on to peers using
1815
// compact block relay.
1916

2017
static void DeserializeBlockTest(benchmark::State& state)
2118
{
22-
CDataStream stream((const char*)block_bench::block413567,
23-
(const char*)block_bench::block413567 + sizeof(block_bench::block413567),
24-
SER_NETWORK, PROTOCOL_VERSION);
19+
CDataStream stream(benchmark::data::block413567, SER_NETWORK, PROTOCOL_VERSION);
2520
char a = '\0';
2621
stream.write(&a, 1); // Prevent compaction
2722

2823
while (state.KeepRunning()) {
2924
CBlock block;
3025
stream >> block;
31-
bool rewound = stream.Rewind(sizeof(block_bench::block413567));
26+
bool rewound = stream.Rewind(benchmark::data::block413567.size());
3227
assert(rewound);
3328
}
3429
}
3530

3631
static void DeserializeAndCheckBlockTest(benchmark::State& state)
3732
{
38-
CDataStream stream((const char*)block_bench::block413567,
39-
(const char*)block_bench::block413567 + sizeof(block_bench::block413567),
40-
SER_NETWORK, PROTOCOL_VERSION);
33+
CDataStream stream(benchmark::data::block413567, SER_NETWORK, PROTOCOL_VERSION);
4134
char a = '\0';
4235
stream.write(&a, 1); // Prevent compaction
4336

@@ -46,7 +39,7 @@ static void DeserializeAndCheckBlockTest(benchmark::State& state)
4639
while (state.KeepRunning()) {
4740
CBlock block; // Note that CBlock caches its checked state, so we need to recreate it here
4841
stream >> block;
49-
bool rewound = stream.Rewind(sizeof(block_bench::block413567));
42+
bool rewound = stream.Rewind(benchmark::data::block413567.size());
5043
assert(rewound);
5144

5245
CValidationState validationState;

src/bench/data.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright (c) 2019 The Bitcoin Core developers
2+
// Distributed under the MIT software license, see the accompanying
3+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4+
5+
#include <bench/data.h>
6+
7+
namespace benchmark {
8+
namespace data {
9+
10+
#include <bench/data/block413567.raw.h>
11+
const std::vector<uint8_t> block413567{block413567_raw, block413567_raw + sizeof(block413567_raw) / sizeof(block413567_raw[0])};
12+
13+
} // namespace data
14+
} // namespace benchmark

src/bench/data.h

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright (c) 2019 The Bitcoin Core developers
2+
// Distributed under the MIT software license, see the accompanying
3+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4+
5+
#ifndef BITCOIN_BENCH_DATA_H
6+
#define BITCOIN_BENCH_DATA_H
7+
8+
#include <cstdint>
9+
#include <vector>
10+
11+
namespace benchmark {
12+
namespace data {
13+
14+
extern const std::vector<uint8_t> block413567;
15+
16+
} // namespace data
17+
} // namespace benchmark
18+
19+
#endif // BITCOIN_BENCH_DATA_H

0 commit comments

Comments
 (0)