Skip to content

Commit f98d1e0

Browse files
author
MarcoFalke
committed
Merge #13711: [bench] Add benchmark for unserialize prevector
46340b3 [bench] Add benchmark for unserialize prevector (Akio Nakamura) Pull request description: This PR adds benchmarks for the unserialization of the prevector. Note: Separated from #12324. Tree-SHA512: c055a283328cc2634c01eb60f26604a8665939bbf77d367b6ba6b4e01e77d4511fab69cc3ddb1e62969adb3c48752ed870f45ceba153eee192302601341e18a7
2 parents 89a116d + 46340b3 commit f98d1e0

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/bench/prevector.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,17 @@
44

55
#include <compat.h>
66
#include <prevector.h>
7+
#include <serialize.h>
8+
#include <streams.h>
79

810
#include <bench/bench.h>
911

1012
struct nontrivial_t {
1113
int x;
1214
nontrivial_t() :x(-1) {}
15+
ADD_SERIALIZE_METHODS
16+
template <typename Stream, typename Operation>
17+
inline void SerializationOp(Stream& s, Operation ser_action) {READWRITE(x);}
1318
};
1419
static_assert(!IS_TRIVIALLY_CONSTRUCTIBLE<nontrivial_t>::value,
1520
"expected nontrivial_t to not be trivially constructible");
@@ -62,6 +67,28 @@ static void PrevectorResize(benchmark::State& state)
6267
}
6368
}
6469

70+
template <typename T>
71+
static void PrevectorDeserialize(benchmark::State& state)
72+
{
73+
CDataStream s0(SER_NETWORK, 0);
74+
prevector<28, T> t0;
75+
t0.resize(28);
76+
for (auto x = 0; x < 900; ++x) {
77+
s0 << t0;
78+
}
79+
t0.resize(100);
80+
for (auto x = 0; x < 101; ++x) {
81+
s0 << t0;
82+
}
83+
while (state.KeepRunning()) {
84+
prevector<28, T> t1;
85+
for (auto x = 0; x < 1000; ++x) {
86+
s0 >> t1;
87+
}
88+
s0.Init(SER_NETWORK, 0);
89+
}
90+
}
91+
6592
#define PREVECTOR_TEST(name, nontrivops, trivops) \
6693
static void Prevector ## name ## Nontrivial(benchmark::State& state) { \
6794
Prevector ## name<nontrivial_t>(state); \
@@ -75,3 +102,4 @@ static void PrevectorResize(benchmark::State& state)
75102
PREVECTOR_TEST(Clear, 28300, 88600)
76103
PREVECTOR_TEST(Destructor, 28800, 88900)
77104
PREVECTOR_TEST(Resize, 28900, 90300)
105+
PREVECTOR_TEST(Deserialize, 6800, 52000)

0 commit comments

Comments
 (0)