Skip to content

Commit e6741d0

Browse files
committed
Add new prevector benchmarks.
>>> backports bitcoin/bitcoin@f0e7aa7 This prepares for a series of two additional commits which optimize prevector performance.
1 parent dc7eb08 commit e6741d0

File tree

4 files changed

+88
-37
lines changed

4 files changed

+88
-37
lines changed

src/Makefile.bench.include

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ bench_bench_pivx_SOURCES = \
1313
bench/crypto_hash.cpp \
1414
bench/perf.cpp \
1515
bench/perf.h \
16-
bench/prevector_destructor.cpp
16+
bench/prevector.cpp
1717

1818
bench_bench_pivx_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) $(EVENT_CFLAGS) $(EVENT_PTHREADS_CFLAGS) -I$(builddir)/bench/
1919
bench_bench_pivx_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)

src/bench/prevector.cpp

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// Copyright (c) 2015-2017 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/bench.h"
6+
7+
#include "compat.h"
8+
#include "prevector.h"
9+
10+
struct nontrivial_t {
11+
int x;
12+
nontrivial_t() :x(-1) {}
13+
};
14+
static_assert(!IS_TRIVIALLY_CONSTRUCTIBLE<nontrivial_t>::value,
15+
"expected nontrivial_t to not be trivially constructible");
16+
17+
typedef unsigned char trivial_t;
18+
static_assert(IS_TRIVIALLY_CONSTRUCTIBLE<trivial_t>::value,
19+
"expected trivial_t to be trivially constructible");
20+
21+
template <typename T>
22+
static void PrevectorDestructor(benchmark::State& state)
23+
{
24+
while (state.KeepRunning()) {
25+
for (auto x = 0; x < 1000; ++x) {
26+
prevector<28, T> t0;
27+
prevector<28, T> t1;
28+
t0.resize(28);
29+
t1.resize(29);
30+
}
31+
}
32+
}
33+
34+
template <typename T>
35+
static void PrevectorClear(benchmark::State& state)
36+
{
37+
38+
while (state.KeepRunning()) {
39+
for (auto x = 0; x < 1000; ++x) {
40+
prevector<28, T> t0;
41+
prevector<28, T> t1;
42+
t0.resize(28);
43+
t0.clear();
44+
t1.resize(29);
45+
t0.clear();
46+
}
47+
}
48+
}
49+
50+
template <typename T>
51+
void PrevectorResize(benchmark::State& state)
52+
{
53+
while (state.KeepRunning()) {
54+
prevector<28, T> t0;
55+
prevector<28, T> t1;
56+
for (auto x = 0; x < 1000; ++x) {
57+
t0.resize(28);
58+
t0.resize(0);
59+
t1.resize(29);
60+
t1.resize(0);
61+
}
62+
}
63+
}
64+
65+
#define PREVECTOR_TEST(name) \
66+
static void Prevector ## name ## Nontrivial(benchmark::State& state) { \
67+
PrevectorResize<nontrivial_t>(state); \
68+
} \
69+
BENCHMARK(Prevector ## name ## Nontrivial); \
70+
static void Prevector ## name ## Trivial(benchmark::State& state) { \
71+
PrevectorResize<trivial_t>(state); \
72+
} \
73+
BENCHMARK(Prevector ## name ## Trivial);
74+
75+
PREVECTOR_TEST(Clear)
76+
PREVECTOR_TEST(Destructor)
77+
PREVECTOR_TEST(Resize)

src/bench/prevector_destructor.cpp

Lines changed: 0 additions & 36 deletions
This file was deleted.

src/compat.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@
1111
#include "config/pivx-config.h"
1212
#endif
1313

14+
#include <type_traits>
15+
16+
// GCC 4.8 is missing some C++11 type_traits,
17+
// https://www.gnu.org/software/gcc/gcc-5/changes.html
18+
#if defined(__GNUC__) && __GNUC__ < 5
19+
#define IS_TRIVIALLY_CONSTRUCTIBLE std::is_trivial
20+
#else
21+
#define IS_TRIVIALLY_CONSTRUCTIBLE std::is_trivially_constructible
22+
#endif
23+
1424
#ifdef WIN32
1525
#ifdef _WIN32_WINNT
1626
#undef _WIN32_WINNT

0 commit comments

Comments
 (0)