fa292724598c273867bc6dbf311f1440fe2541ba Remove redundant MakeUCharSpan wrappers (MarcoFalke)
faf4aa2f47c0de4f3a0c5f5fe5b3ec32f611eefd Remove CDataStream::Init in favor of C++11 member initialization (MarcoFalke)
fada14b948cac147198e3b685b5dd8cb72dc2911 Treat CDataStream bytes as uint8_t (MarcoFalke)
fa8bdb048e65cae2d26bea3f991717a856e2fb39 refactor: Drop CDataStream constructors in favor of one taking a Span of bytes (MarcoFalke)
faa96f841fe45bc49ebb6e07ac82a129fa9c40bf Remove unused CDataStream methods (MarcoFalke)
Pull request description:
Using `uint8_t` for raw bytes has a style benefit:
* The signedness is clear from reading the code, as it does not depend on the architecture
Other clean-ups in this pull include:
* Remove unused methods
* Constructor is simplified with `Span`
* Remove `Init()` member in favor of C++11 member initialization
ACKs for top commit:
laanwj:
code review ACK fa292724598c273867bc6dbf311f1440fe2541ba
theStack:
ACK fa292724598c273867bc6dbf311f1440fe2541ba 🍾
Tree-SHA512: 931ee28bd99843d7e894b48e90e1187ffb0278677c267044b3c0c255069d9bbd9298ab2e539b1002a30b543d240450eaec718ef4ee95a7fd4be0a295e926343f
99 lines
2.8 KiB
C++
99 lines
2.8 KiB
C++
// Copyright (c) 2015-2020 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 <prevector.h>
|
|
#include <serialize.h>
|
|
#include <streams.h>
|
|
#include <type_traits>
|
|
|
|
#include <bench/bench.h>
|
|
|
|
struct nontrivial_t {
|
|
int x;
|
|
nontrivial_t() :x(-1) {}
|
|
SERIALIZE_METHODS(nontrivial_t, obj) { READWRITE(obj.x); }
|
|
};
|
|
static_assert(!std::is_trivially_default_constructible<nontrivial_t>::value,
|
|
"expected nontrivial_t to not be trivially constructible");
|
|
|
|
typedef unsigned char trivial_t;
|
|
static_assert(std::is_trivially_default_constructible<trivial_t>::value,
|
|
"expected trivial_t to be trivially constructible");
|
|
|
|
template <typename T>
|
|
static void PrevectorDestructor(benchmark::Bench& bench)
|
|
{
|
|
bench.batch(2).run([&] {
|
|
prevector<28, T> t0;
|
|
prevector<28, T> t1;
|
|
t0.resize(28);
|
|
t1.resize(29);
|
|
});
|
|
}
|
|
|
|
template <typename T>
|
|
static void PrevectorClear(benchmark::Bench& bench)
|
|
{
|
|
prevector<28, T> t0;
|
|
prevector<28, T> t1;
|
|
bench.batch(2).run([&] {
|
|
t0.resize(28);
|
|
t0.clear();
|
|
t1.resize(29);
|
|
t1.clear();
|
|
});
|
|
}
|
|
|
|
template <typename T>
|
|
static void PrevectorResize(benchmark::Bench& bench)
|
|
{
|
|
prevector<28, T> t0;
|
|
prevector<28, T> t1;
|
|
bench.batch(4).run([&] {
|
|
t0.resize(28);
|
|
t0.resize(0);
|
|
t1.resize(29);
|
|
t1.resize(0);
|
|
});
|
|
}
|
|
|
|
template <typename T>
|
|
static void PrevectorDeserialize(benchmark::Bench& bench)
|
|
{
|
|
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;
|
|
}
|
|
bench.batch(1000).run([&] {
|
|
prevector<28, T> t1;
|
|
for (auto x = 0; x < 1000; ++x) {
|
|
s0 >> t1;
|
|
}
|
|
s0.Rewind();
|
|
});
|
|
}
|
|
|
|
#define PREVECTOR_TEST(name) \
|
|
static void Prevector##name##Nontrivial(benchmark::Bench& bench) \
|
|
{ \
|
|
Prevector##name<nontrivial_t>(bench); \
|
|
} \
|
|
BENCHMARK(Prevector##name##Nontrivial); \
|
|
static void Prevector##name##Trivial(benchmark::Bench& bench) \
|
|
{ \
|
|
Prevector##name<trivial_t>(bench); \
|
|
} \
|
|
BENCHMARK(Prevector##name##Trivial);
|
|
|
|
PREVECTOR_TEST(Clear)
|
|
PREVECTOR_TEST(Destructor)
|
|
PREVECTOR_TEST(Resize)
|
|
PREVECTOR_TEST(Deserialize)
|