From 9ba1c20d1eeec5f4aedf9dcb05c5768a897cbd2c Mon Sep 17 00:00:00 2001 From: Lars Date: Fri, 20 Jun 2025 12:15:04 -0700 Subject: [PATCH] Add test benchmark for Map --- src/benchmark/CMakeLists.txt | 1 + src/benchmark/benchmark_map.cpp | 177 ++++++++++++++++++++++++++++++++ 2 files changed, 178 insertions(+) create mode 100644 src/benchmark/benchmark_map.cpp diff --git a/src/benchmark/CMakeLists.txt b/src/benchmark/CMakeLists.txt index e8150848a..bf2bf15db 100644 --- a/src/benchmark/CMakeLists.txt +++ b/src/benchmark/CMakeLists.txt @@ -4,6 +4,7 @@ set (BENCHMARK_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/benchmark_lighting.cpp ${CMAKE_CURRENT_SOURCE_DIR}/benchmark_serialize.cpp ${CMAKE_CURRENT_SOURCE_DIR}/benchmark_mapblock.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/benchmark_map.cpp ${CMAKE_CURRENT_SOURCE_DIR}/benchmark_mapmodify.cpp ${CMAKE_CURRENT_SOURCE_DIR}/benchmark_sha.cpp PARENT_SCOPE) diff --git a/src/benchmark/benchmark_map.cpp b/src/benchmark/benchmark_map.cpp new file mode 100644 index 000000000..0658b6ccb --- /dev/null +++ b/src/benchmark/benchmark_map.cpp @@ -0,0 +1,177 @@ +// Luanti +// SPDX-License-Identifier: LGPL-2.1-or-later +// Copyright (C) 2023 Minetest Authors + +#include "catch.h" +#include "dummygamedef.h" +#include "map.h" +#include "mapsector.h" + +class TestMap : public Map { +public: + TestMap(IGameDef *gamedef) : Map(gamedef) {} + + MapBlock * createBlockTest(v3s16 p) + { + v2s16 p2d(p.X, p.Z); + s16 block_y = p.Y; + + MapSector *sector = getSectorNoGenerate(p2d); + if (!sector) { + sector = new MapSector(this, p2d, m_gamedef); + m_sectors[p2d] = sector; + } + + MapBlock *block = sector->getBlockNoCreateNoEx(block_y); + if (block) + return block; + + return sector->createBlankBlock(block_y); + } + +}; + +static void fillMap(TestMap &map, s16 n) +{ + for(s16 z=0; z0; y--) { + v3s16 p(x,y,z); + MapBlock *block = map.getBlockNoCreateNoEx(p); + if (block) { + result++; + } + } + return result; +} + +static int readNodes(Map &map, s16 n) +{ + int result = 0; + for(s16 z=0; z