Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions src/Makefile.bench.include
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
# Copyright (c) 2015-2021 The Bitcoin Core developers
# Copyright (c) 2020-2021 The PIVX Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.

bin_PROGRAMS += bench/bench_pivx
BENCH_SRCDIR = bench
BENCH_BINARY = bench/bench_pivx$(EXEEXT)

RAW_TEST_FILES = \
RAW_BENCH_FILES = \
bench/data/block2680960.raw

GENERATED_TEST_FILES = $(RAW_TEST_FILES:.raw=.raw.h)
GENERATED_BENCH_FILES = $(RAW_BENCH_FILES:.raw=.raw.h)

bench_bench_pivx_SOURCES = \
$(RAW_BENCH_FILES) \
bench/bench_pivx.cpp \
bench/bench.cpp \
bench/bench.h \
bench/Examples.cpp \
bench/base58.cpp \
bench/checkblock.cpp \
bench/checkqueue.cpp \
bench/data.h \
bench/data.cpp \
bench/chacha20.cpp \
bench/crypto_hash.cpp \
bench/lockedpool.cpp \
Expand All @@ -23,7 +30,7 @@ bench_bench_pivx_SOURCES = \
bench/prevector.cpp \
bench/util_time.cpp

nodist_bench_bench_pivx_SOURCES = $(GENERATED_TEST_FILES)
nodist_bench_bench_pivx_SOURCES = $(GENERATED_BENCH_FILES)

bench_bench_pivx_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) $(EVENT_CFLAGS) $(EVENT_PTHREADS_CFLAGS) -I$(builddir)/bench/
bench_bench_pivx_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
Expand All @@ -50,12 +57,11 @@ endif
bench_bench_pivx_LDADD += $(LIBBITCOIN_CONSENSUS) $(BOOST_LIBS) $(BDB_LIBS) $(MINIUPNPC_LIBS) $(NATPMP_LIBS) $(EVENT_PTHREADS_LIBS) $(EVENT_LIBS)
bench_bench_pivx_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)

# !TODO: .raw.h generated test files are not removed with make clean
CLEAN_BITCOIN_BENCH = bench/*.gcda bench/*.gcno $(GENERATED_TEST_FILES)
CLEAN_BITCOIN_BENCH = bench/*.gcda bench/*.gcno $(GENERATED_BENCH_FILES)

CLEANFILES += $(CLEAN_BITCOIN_BENCH)

bench/checkblock.cpp: bench/data/block2680960.raw.h
bench/data.cpp: bench/data/block2680960.raw.h

bitcoin_bench: $(BENCH_BINARY)

Expand All @@ -68,7 +74,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" "$@"
Expand Down
25 changes: 10 additions & 15 deletions src/bench/checkblock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,42 @@
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include "bench.h"
#include "bench/bench.h"
#include "bench/data.h"

#include "validation.h"

namespace block_bench {
#include "bench/data/block2680960.raw.h"
}

// 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::block2680960,
(const char*)&block_bench::block2680960[sizeof(block_bench::block2680960)],
SER_NETWORK, PROTOCOL_VERSION);
char a;
CDataStream stream(benchmark::data::block2680960, SER_NETWORK, PROTOCOL_VERSION);
char a = '\0';
stream.write(&a, 1); // Prevent compaction

while (state.KeepRunning()) {
CBlock block;
stream >> block;
assert(stream.Rewind(sizeof(block_bench::block2680960)));
bool rewound = stream.Rewind(benchmark::data::block2680960.size());
assert(rewound);
}
}

static void DeserializeAndCheckBlockTest(benchmark::State& state)
{
CDataStream stream((const char*)block_bench::block2680960,
(const char*)&block_bench::block2680960[sizeof(block_bench::block2680960)],
SER_NETWORK, PROTOCOL_VERSION);
char a;
CDataStream stream(benchmark::data::block2680960, SER_NETWORK, PROTOCOL_VERSION);
char a = '\0';
stream.write(&a, 1); // Prevent compaction

SelectParams(CBaseChainParams::MAIN);

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

CValidationState state;
assert(CheckBlock(block, state));
Expand Down
14 changes: 14 additions & 0 deletions src/bench/data.cpp
Original file line number Diff line number Diff line change
@@ -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/block2680960.raw.h>
const std::vector<uint8_t> block2680960{block2680960_raw, block2680960_raw + sizeof(block2680960_raw) / sizeof(block2680960_raw[0])};

} // namespace data
} // namespace benchmark
19 changes: 19 additions & 0 deletions src/bench/data.h
Original file line number Diff line number Diff line change
@@ -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> block2680960;

} // namespace data
} // namespace benchmark

#endif // BITCOIN_BENCH_DATA_H