aboutsummaryrefslogtreecommitdiff
path: root/src/bench
diff options
context:
space:
mode:
authorAkio Nakamura <nakamura@dgtechnologies.co.jp>2018-07-08 00:19:29 +0900
committerAkio Nakamura <nakamura@dgtechnologies.co.jp>2018-07-20 17:57:01 +0900
commit46340b3337b7ef9fa68030e9c4b2092a25874837 (patch)
treebc9311ee5759e129f81faa8f70b0cc90d49dbe31 /src/bench
parent4a3e8c5aa6a5d8dda15a76d644b2a9f0f40cdec7 (diff)
downloadbitcoin-46340b3337b7ef9fa68030e9c4b2092a25874837.tar.xz
[bench] Add benchmark for unserialize prevector
This patch adds 2 benchmarks to measure for performance of the unserialization of prevector.
Diffstat (limited to 'src/bench')
-rw-r--r--src/bench/prevector.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/bench/prevector.cpp b/src/bench/prevector.cpp
index 09c7020848..7986d0da79 100644
--- a/src/bench/prevector.cpp
+++ b/src/bench/prevector.cpp
@@ -4,12 +4,17 @@
#include <compat.h>
#include <prevector.h>
+#include <serialize.h>
+#include <streams.h>
#include <bench/bench.h>
struct nontrivial_t {
int x;
nontrivial_t() :x(-1) {}
+ ADD_SERIALIZE_METHODS
+ template <typename Stream, typename Operation>
+ inline void SerializationOp(Stream& s, Operation ser_action) {READWRITE(x);}
};
static_assert(!IS_TRIVIALLY_CONSTRUCTIBLE<nontrivial_t>::value,
"expected nontrivial_t to not be trivially constructible");
@@ -62,6 +67,28 @@ static void PrevectorResize(benchmark::State& state)
}
}
+template <typename T>
+static void PrevectorDeserialize(benchmark::State& state)
+{
+ CDataStream s0(SER_NETWORK, 0);
+ prevector<28, T> t0;
+ t0.resize(28);
+ for (auto x = 0; x < 900; ++x) {
+ s0 << t0;
+ }
+ t0.resize(100);
+ for (auto x = 0; x < 101; ++x) {
+ s0 << t0;
+ }
+ while (state.KeepRunning()) {
+ prevector<28, T> t1;
+ for (auto x = 0; x < 1000; ++x) {
+ s0 >> t1;
+ }
+ s0.Init(SER_NETWORK, 0);
+ }
+}
+
#define PREVECTOR_TEST(name, nontrivops, trivops) \
static void Prevector ## name ## Nontrivial(benchmark::State& state) { \
Prevector ## name<nontrivial_t>(state); \
@@ -75,3 +102,4 @@ static void PrevectorResize(benchmark::State& state)
PREVECTOR_TEST(Clear, 28300, 88600)
PREVECTOR_TEST(Destructor, 28800, 88900)
PREVECTOR_TEST(Resize, 28900, 90300)
+PREVECTOR_TEST(Deserialize, 6800, 52000)