Skip to content

Commit 295e2d4

Browse files
committed
bench: Move generated data to a dedicated translation unit
Idea coming from btc@3d60a03a7cfb2d46b5f10633e9f6a9a36b8cb76f
1 parent b82d08a commit 295e2d4

File tree

4 files changed

+46
-16
lines changed

4 files changed

+46
-16
lines changed

src/Makefile.bench.include

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ bench_bench_pivx_SOURCES = \
1515
bench/base58.cpp \
1616
bench/checkblock.cpp \
1717
bench/checkqueue.cpp \
18+
bench/data.h \
19+
bench/data.cpp \
1820
bench/chacha20.cpp \
1921
bench/crypto_hash.cpp \
2022
bench/lockedpool.cpp \
@@ -55,7 +57,7 @@ CLEAN_BITCOIN_BENCH = bench/*.gcda bench/*.gcno $(GENERATED_TEST_FILES)
5557

5658
CLEANFILES += $(CLEAN_BITCOIN_BENCH)
5759

58-
bench/checkblock.cpp: bench/data/block2680960.raw.h
60+
bench/data.cpp: bench/data/block2680960.raw.h
5961

6062
bitcoin_bench: $(BENCH_BINARY)
6163

src/bench/checkblock.cpp

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,47 +2,42 @@
22
// Distributed under the MIT software license, see the accompanying
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

5-
#include "bench.h"
5+
#include "bench/bench.h"
6+
#include "bench/data.h"
67

78
#include "validation.h"
89

9-
namespace block_bench {
10-
#include "bench/data/block2680960.raw.h"
11-
}
12-
1310
// These are the two major time-sinks which happen after we have fully received
1411
// a block off the wire, but before we can relay the block on to peers using
1512
// compact block relay.
1613

1714
static void DeserializeBlockTest(benchmark::State& state)
1815
{
19-
CDataStream stream((const char*)block_bench::block2680960,
20-
(const char*)&block_bench::block2680960[sizeof(block_bench::block2680960)],
21-
SER_NETWORK, PROTOCOL_VERSION);
22-
char a;
16+
CDataStream stream(benchmark::data::block2680960, SER_NETWORK, PROTOCOL_VERSION);
17+
char a = '\0';
2318
stream.write(&a, 1); // Prevent compaction
2419

2520
while (state.KeepRunning()) {
2621
CBlock block;
2722
stream >> block;
28-
assert(stream.Rewind(sizeof(block_bench::block2680960)));
23+
bool rewound = stream.Rewind(benchmark::data::block2680960.size());
24+
assert(rewound);
2925
}
3026
}
3127

3228
static void DeserializeAndCheckBlockTest(benchmark::State& state)
3329
{
34-
CDataStream stream((const char*)block_bench::block2680960,
35-
(const char*)&block_bench::block2680960[sizeof(block_bench::block2680960)],
36-
SER_NETWORK, PROTOCOL_VERSION);
37-
char a;
30+
CDataStream stream(benchmark::data::block2680960, SER_NETWORK, PROTOCOL_VERSION);
31+
char a = '\0';
3832
stream.write(&a, 1); // Prevent compaction
3933

4034
SelectParams(CBaseChainParams::MAIN);
4135

4236
while (state.KeepRunning()) {
4337
CBlock block; // Note that CBlock caches its checked state, so we need to recreate it here
4438
stream >> block;
45-
assert(stream.Rewind(sizeof(block_bench::block2680960)));
39+
bool rewound = stream.Rewind(benchmark::data::block2680960.size());
40+
assert(rewound);
4641

4742
CValidationState state;
4843
assert(CheckBlock(block, state));

src/bench/data.cpp

Lines changed: 14 additions & 0 deletions
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/block2680960.raw.h>
11+
const std::vector<uint8_t> block2680960{block2680960_raw, block2680960_raw + sizeof(block2680960_raw) / sizeof(block2680960_raw[0])};
12+
13+
} // namespace data
14+
} // namespace benchmark

src/bench/data.h

Lines changed: 19 additions & 0 deletions
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> block2680960;
15+
16+
} // namespace data
17+
} // namespace benchmark
18+
19+
#endif // BITCOIN_BENCH_DATA_H

0 commit comments

Comments
 (0)