Browse Source

Add more palette blending benchmarks

Adds separate benchmarks for building the tree vs lookup

    BM_GenerateBlendedLookupTable    2247062 ns      2246554 ns          312
    BM_BuildTree                        6842 ns         6840 ns       102200
    BM_FindNearestNeighbor        2535103632 ns   2534784320 ns            1 items_per_second=6.61879M/s
pull/8040/head
Gleb Mazovetskiy 9 months ago
parent
commit
4a22002769
  1. 38
      test/palette_blending_benchmark.cpp

38
test/palette_blending_benchmark.cpp

@ -1,10 +1,13 @@
#include "utils/palette_blending.hpp"
#include <array>
#include <cstdint>
#include <SDL.h>
#include <benchmark/benchmark.h>
#include "utils/palette_kd_tree.hpp"
namespace devilution {
std::array<SDL_Color, 256> logical_palette;
@ -36,7 +39,42 @@ void BM_GenerateBlendedLookupTable(benchmark::State &state)
}
}
void BM_BuildTree(benchmark::State &state)
{
SDL_Color *palette = logical_palette.data();
GeneratePalette(palette);
for (auto _ : state) {
PaletteKdTree tree(palette, -1, -1);
benchmark::DoNotOptimize(tree);
}
}
void BM_FindNearestNeighbor(benchmark::State &state)
{
SDL_Color *palette = logical_palette.data();
GeneratePalette(palette);
PaletteKdTree tree(palette, -1, -1);
std::vector<std::array<uint8_t, 3>> queries;
int64_t itemsProcessed = 0;
for (auto _ : state) {
for (int r = 0; r < 256; ++r) {
for (int g = 0; g < 256; ++g) {
for (int b = 0; b < 256; ++b) {
uint8_t result = tree.findNearestNeighbor({ static_cast<uint8_t>(r), static_cast<uint8_t>(g), static_cast<uint8_t>(b) });
benchmark::DoNotOptimize(result);
}
}
}
itemsProcessed += 256 * 256 * 256;
}
state.SetItemsProcessed(itemsProcessed);
}
BENCHMARK(BM_GenerateBlendedLookupTable);
BENCHMARK(BM_BuildTree);
BENCHMARK(BM_FindNearestNeighbor);
} // namespace
} // namespace devilution

Loading…
Cancel
Save