Luanti 5.10.0-dev
 
Loading...
Searching...
No Matches
benchmark_mapmodify.cpp File Reference
#include "catch.h"
#include "util/container.h"
+ Include dependency graph for benchmark_mapmodify.cpp:

Macros

#define BENCH_ITERATE_(_label, _count, _best)
 
#define BENCH_ITERATE(_count)
 
#define BENCH_REMOVE(_count)
 
#define BENCH2_ITERATE(_count)
 
#define BENCH2_REMOVE(_count)
 

Typedefs

using TestMap = ModifySafeMap<u16, void*>
 
using TestMap2 = std::map<u16, void*>
 

Functions

static void fill (TestMap &map, size_t n)
 
static void pollute (TestMap &map)
 
static void remove (TestMap &map, size_t offset, size_t count)
 
 TEST_CASE ("ModifySafeMap")
 
static void fill2 (TestMap2 &map, size_t n)
 
static void remove2 (TestMap2 &map, size_t offset, size_t count)
 

Macro Definition Documentation

◆ BENCH2_ITERATE

#define BENCH2_ITERATE ( _count)
Value:
BENCHMARK_ADVANCED("iterate_" #_count)(Catch::Benchmark::Chronometer meter) { \
TestMap2 map; \
fill2(map, _count); \
meter.measure([&] { \
size_t x = map.size(); \
/* mirrors what ActiveObjectMgr::step used to do */ \
std::vector<TestMap2::key_type> keys; \
keys.reserve(x); \
for (auto &it : map) \
keys.push_back(it.first); \
for (auto key : keys) { \
auto it = map.find(key); \
if (it == map.end()) \
continue; \
x ^= reinterpret_cast<intptr_t>(it->second); \
} \
return x; \
}); \
};
std::map< u16, void * > TestMap2
Definition benchmark_mapmodify.cpp:81

◆ BENCH2_REMOVE

#define BENCH2_REMOVE ( _count)
Value:
BENCHMARK_ADVANCED("remove_" #_count)(Catch::Benchmark::Chronometer meter) { \
TestMap2 map; \
fill2(map, _count); \
meter.measure([&] { \
/* no overhead so no fake iteration */ \
remove2(map, (_count) / 7, (_count) / 2); \
}); \
};

◆ BENCH_ITERATE

#define BENCH_ITERATE ( _count)
Value:
BENCH_ITERATE_("iterate_" #_count, _count, 0) \
BENCH_ITERATE_("iterate_bestcase_" #_count, _count, 1)
#define BENCH_ITERATE_(_label, _count, _best)
Definition benchmark_mapmodify.cpp:38

Referenced by TEST_CASE().

◆ BENCH_ITERATE_

#define BENCH_ITERATE_ ( _label,
_count,
_best )
Value:
BENCHMARK_ADVANCED(_label)(Catch::Benchmark::Chronometer meter) { \
TestMap map; \
fill(map, _count); \
if (!_best) pollute(map); \
meter.measure([&] { \
size_t x = map.size(); \
for (auto &it : map.iter()) { \
if (!it.second) \
continue; \
x ^= reinterpret_cast<intptr_t>(it.second); \
} \
return x; \
}); \
};
static void pollute(TestMap &map)
Definition benchmark_mapmodify.cpp:20
Definition test_map.cpp:28

◆ BENCH_REMOVE

#define BENCH_REMOVE ( _count)
Value:
BENCHMARK_ADVANCED("remove_" #_count)(Catch::Benchmark::Chronometer meter) { \
TestMap map; \
fill(map, _count); \
meter.measure([&] { \
for (auto it : map.iter()) { \
(void)it; \
remove(map, (_count) / 7, (_count) / 2); /* delete half */ \
break; \
} \
}); \
};

Referenced by TEST_CASE().

Typedef Documentation

◆ TestMap

using TestMap = ModifySafeMap<u16, void*>

◆ TestMap2

using TestMap2 = std::map<u16, void*>

Function Documentation

◆ fill()

static void fill ( TestMap & map,
size_t n )
inlinestatic

Referenced by benchGetObjectsInArea(), and benchGetObjectsInsideRadius().

+ Here is the caller graph for this function:

◆ fill2()

static void fill2 ( TestMap2 & map,
size_t n )
inlinestatic

◆ pollute()

static void pollute ( TestMap & map)
inlinestatic

◆ remove()

static void remove ( TestMap & map,
size_t offset,
size_t count )
inlinestatic

Referenced by EventManager::dereg(), ScriptApiSecurity::initializeSecurity(), ModStorageDatabaseSQLite3::initStatements(), GUIModalMenu::quitMenu(), and fs::safeWriteToFile().

+ Here is the caller graph for this function:

◆ remove2()

static void remove2 ( TestMap2 & map,
size_t offset,
size_t count )
inlinestatic

◆ TEST_CASE()

TEST_CASE ( "ModifySafeMap" )

References BENCH_ITERATE, and BENCH_REMOVE.