Dash Core Source Documentation (0.16.0.1)

Find detailed information regarding the Dash Core source code.

prevector.cpp
Go to the documentation of this file.
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 <compat.h>
6 #include <prevector.h>
7 
8 #include <bench/bench.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>
23 {
24  while (state.KeepRunning()) {
25  for (auto x = 0; x < 1000; ++x) {
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) {
42  t0.resize(28);
43  t0.clear();
44  t1.resize(29);
45  t0.clear();
46  }
47  }
48 }
49 
50 template <typename T>
52 {
53  while (state.KeepRunning()) {
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, nontrivops, trivops) \
66  static void Prevector ## name ## Nontrivial(benchmark::State& state) { \
67  PrevectorResize<nontrivial_t>(state); \
68  } \
69  BENCHMARK(Prevector ## name ## Nontrivial/*, nontrivops*/); \
70  static void Prevector ## name ## Trivial(benchmark::State& state) { \
71  PrevectorResize<trivial_t>(state); \
72  } \
73  BENCHMARK(Prevector ## name ## Trivial/*, trivops*/);
74 
75 PREVECTOR_TEST(Clear, 28300, 88600)
76 PREVECTOR_TEST(Destructor, 28800, 88900)
77 PREVECTOR_TEST(Resize, 28900, 90300)
78 
79 #include <vector>
80 
82 
83 static void PrevectorAssign(benchmark::State& state)
84 {
85  prevec t;
86  t.resize(28);
87  std::vector<unsigned char> v;
88  while (state.KeepRunning()) {
89  for (int i = 0; i < 1000; ++i) {
90  prevec::const_iterator b = t.begin() + 5;
91  prevec::const_iterator e = b + 20;
92  v.assign(b, e);
93  }
94  }
95 }
96 
98 {
99  prevec t;
100  t.resize(28);
101  std::vector<unsigned char> v;
102  while (state.KeepRunning()) {
103  for (int i = 0; i < 1000; ++i) {
104  prevec::const_iterator b = t.begin() + 5;
105  prevec::const_iterator e = b + 20;
106  t.assign_to(b, e, v);
107  }
108  }
109 }
110 
void resize(size_type new_size)
Definition: prevector.h:344
#define BENCHMARK(n)
Definition: bench.h:92
static void PrevectorDestructor(benchmark::State &state)
Definition: prevector.cpp:22
void clear()
Definition: prevector.h:371
bool KeepRunning()
Definition: bench.cpp:39
void PrevectorResize(benchmark::State &state)
Definition: prevector.cpp:51
static void PrevectorAssign(benchmark::State &state)
Definition: prevector.cpp:83
#define PREVECTOR_TEST(name, nontrivops, trivops)
Definition: prevector.cpp:65
static void PrevectorClear(benchmark::State &state)
Definition: prevector.cpp:35
static void PrevectorAssignTo(benchmark::State &state)
Definition: prevector.cpp:97
unsigned char trivial_t
Definition: prevector.cpp:15
Implements a drop-in replacement for std::vector<T> which stores up to N elements directly (without h...
Definition: prevector.h:39
prevector< 28, unsigned char > prevec
Definition: prevector.cpp:81
iterator begin()
Definition: prevector.h:318
static void assign_to(const_iterator b, const_iterator e, V &v)
Definition: prevector.h:560
Released under the MIT license