Luanti 5.11.0-dev
 
Loading...
Searching...
No Matches
benchmark_serialize.cpp File Reference
#include "catch.h"
#include "util/serialize.h"
#include <sstream>
#include <ios>
+ Include dependency graph for benchmark_serialize.cpp:

Macros

#define BENCH3(_label, _chars, _length, _lengthlabel)
 
#define BENCH2(_label, _chars, _length, _lengthlabel)
 
#define BENCH1(_label, _chars)
 
#define BENCH_ALL()
 

Functions

static std::string makeRepeatTo (const std::string &s, size_t length)
 
 TEST_CASE ("benchmark_serialize")
 

Macro Definition Documentation

◆ BENCH1

#define BENCH1 ( _label,
_chars )
Value:
BENCH2(_label, _chars, 10, "small") \
BENCH2(_label, _chars, 10000, "large")
#define BENCH2(_label, _chars, _length, _lengthlabel)
Definition benchmark_serialize.cpp:39

◆ BENCH2

#define BENCH2 ( _label,
_chars,
_length,
_lengthlabel )
Value:
BENCH3(_label, _chars, _length, _lengthlabel) \
BENCH3(_label "_with_space", " " _chars, _length, _lengthlabel) \
#define BENCH3(_label, _chars, _length, _lengthlabel)
Definition benchmark_serialize.cpp:22

◆ BENCH3

#define BENCH3 ( _label,
_chars,
_length,
_lengthlabel )
Value:
BENCHMARK_ADVANCED("serializeJsonStringIfNeeded_" _lengthlabel "_" _label)(Catch::Benchmark::Chronometer meter) { \
std::string s = makeRepeatTo(_chars, _length); \
meter.measure([&] { return serializeJsonStringIfNeeded(s); }); \
}; \
BENCHMARK_ADVANCED("deSerializeJsonStringIfNeeded_" _lengthlabel "_" _label)(Catch::Benchmark::Chronometer meter) { \
std::string s = makeRepeatTo(_chars, _length); \
std::string serialized = serializeJsonStringIfNeeded(s); \
std::istringstream is(serialized, std::ios::binary); \
meter.measure([&] { \
is.clear(); \
is.seekg(0, std::ios::beg); \
}); \
};
static std::string makeRepeatTo(const std::string &s, size_t length)
Definition benchmark_serialize.cpp:11
std::string serializeJsonStringIfNeeded(std::string_view s)
Definition serialize.cpp:251
std::string deSerializeJsonStringIfNeeded(std::istream &is)
Definition serialize.cpp:260

◆ BENCH_ALL

#define BENCH_ALL ( )
Value:
BENCH1("alpha", "abcdefghijklmnopqrstuvwxyz") \
BENCH1("escaped", "\"\\/\b\f\n\r\t") \
BENCH1("nonascii", "\xf0\xff")
#define BENCH1(_label, _chars)
Definition benchmark_serialize.cpp:44

Referenced by TEST_CASE().

Function Documentation

◆ makeRepeatTo()

static std::string makeRepeatTo ( const std::string & s,
size_t length )
static

◆ TEST_CASE()

TEST_CASE ( "benchmark_serialize" )

References BENCH_ALL.