aboutsummaryrefslogtreecommitdiff
path: root/src/bench
diff options
context:
space:
mode:
authorJoão Barbosa <joao.paulo.barbosa@gmail.com>2019-07-01 21:42:22 +0100
committerJoão Barbosa <joao.paulo.barbosa@gmail.com>2019-07-02 18:11:15 +0100
commit3d60a03a7cfb2d46b5f10633e9f6a9a36b8cb76f (patch)
treec9331766a3fa5b11dba590a0f968f36472e6a1c0 /src/bench
parent3077f11dadffbc8f2575449fc0177c91a9c3e046 (diff)
downloadbitcoin-3d60a03a7cfb2d46b5f10633e9f6a9a36b8cb76f.tar.xz
bench: Move generated data to a dedicated translation unit
Diffstat (limited to 'src/bench')
-rw-r--r--src/bench/checkblock.cpp17
-rw-r--r--src/bench/data.cpp14
-rw-r--r--src/bench/data.h19
3 files changed, 38 insertions, 12 deletions
diff --git a/src/bench/checkblock.cpp b/src/bench/checkblock.cpp
index e325333c01..4b13381e16 100644
--- a/src/bench/checkblock.cpp
+++ b/src/bench/checkblock.cpp
@@ -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;
diff --git a/src/bench/data.cpp b/src/bench/data.cpp
new file mode 100644
index 0000000000..0ae4c7cad4
--- /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 <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
diff --git a/src/bench/data.h b/src/bench/data.h
new file mode 100644
index 0000000000..5f13d766ea
--- /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 <cstdint>
+#include <vector>
+
+namespace benchmark {
+namespace data {
+
+extern const std::vector<uint8_t> block413567;
+
+} // namespace data
+} // namespace benchmark
+
+#endif // BITCOIN_BENCH_DATA_H