Skip to content

Commit

Permalink
Add new prevector benchmarks.
Browse files Browse the repository at this point in the history
>>> backports bitcoin/bitcoin@f0e7aa7

This prepares for a series of two additional commits which optimize
prevector performance.

Github-Pull: PIVX-Project#2083
Rebased-From: e6741d0
  • Loading branch information
random-zebra authored and Fuzzbawls committed Dec 21, 2020
1 parent 04756ee commit e6ffe2a
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 37 deletions.
2 changes: 1 addition & 1 deletion src/Makefile.bench.include
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ bench_bench_pivx_SOURCES = \
bench/crypto_hash.cpp \
bench/perf.cpp \
bench/perf.h \
bench/prevector_destructor.cpp
bench/prevector.cpp

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 Down
77 changes: 77 additions & 0 deletions src/bench/prevector.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// Copyright (c) 2015-2017 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/bench.h"

#include "compat.h"
#include "prevector.h"

struct nontrivial_t {
int x;
nontrivial_t() :x(-1) {}
};
static_assert(!IS_TRIVIALLY_CONSTRUCTIBLE<nontrivial_t>::value,
"expected nontrivial_t to not be trivially constructible");

typedef unsigned char trivial_t;
static_assert(IS_TRIVIALLY_CONSTRUCTIBLE<trivial_t>::value,
"expected trivial_t to be trivially constructible");

template <typename T>
static void PrevectorDestructor(benchmark::State& state)
{
while (state.KeepRunning()) {
for (auto x = 0; x < 1000; ++x) {
prevector<28, T> t0;
prevector<28, T> t1;
t0.resize(28);
t1.resize(29);
}
}
}

template <typename T>
static void PrevectorClear(benchmark::State& state)
{

while (state.KeepRunning()) {
for (auto x = 0; x < 1000; ++x) {
prevector<28, T> t0;
prevector<28, T> t1;
t0.resize(28);
t0.clear();
t1.resize(29);
t0.clear();
}
}
}

template <typename T>
void PrevectorResize(benchmark::State& state)
{
while (state.KeepRunning()) {
prevector<28, T> t0;
prevector<28, T> t1;
for (auto x = 0; x < 1000; ++x) {
t0.resize(28);
t0.resize(0);
t1.resize(29);
t1.resize(0);
}
}
}

#define PREVECTOR_TEST(name) \
static void Prevector ## name ## Nontrivial(benchmark::State& state) { \
PrevectorResize<nontrivial_t>(state); \
} \
BENCHMARK(Prevector ## name ## Nontrivial); \
static void Prevector ## name ## Trivial(benchmark::State& state) { \
PrevectorResize<trivial_t>(state); \
} \
BENCHMARK(Prevector ## name ## Trivial);

PREVECTOR_TEST(Clear)
PREVECTOR_TEST(Destructor)
PREVECTOR_TEST(Resize)
36 changes: 0 additions & 36 deletions src/bench/prevector_destructor.cpp

This file was deleted.

10 changes: 10 additions & 0 deletions src/compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@
#include "config/pivx-config.h"
#endif

#include <type_traits>

// GCC 4.8 is missing some C++11 type_traits,
// https://www.gnu.org/software/gcc/gcc-5/changes.html
#if defined(__GNUC__) && __GNUC__ < 5
#define IS_TRIVIALLY_CONSTRUCTIBLE std::is_trivial
#else
#define IS_TRIVIALLY_CONSTRUCTIBLE std::is_trivially_constructible
#endif

#ifdef WIN32
#ifdef _WIN32_WINNT
#undef _WIN32_WINNT
Expand Down

0 comments on commit e6ffe2a

Please sign in to comment.