|
| 1 | +#include <Video/RendererSIMD.hpp> |
| 2 | +#include <Video/RendererSoftware.hpp> |
| 3 | + |
| 4 | +#include <array> |
| 5 | +#include <chrono> |
| 6 | +#include <print> |
| 7 | +#include <string_view> |
| 8 | + |
| 9 | +static constexpr size_t WIDTH = 768; |
| 10 | +static constexpr size_t HEIGHT = 280; |
| 11 | +static constexpr size_t FRAMES = 10000; |
| 12 | +static constexpr size_t FRAMES_CURSOR = 10'000'000; |
| 13 | + |
| 14 | +static constexpr std::array<uint8_t, WIDTH> LINEA{}; |
| 15 | +static constexpr std::array<uint8_t, WIDTH> LINEB{}; |
| 16 | + |
| 17 | +static constexpr Video::Renderer::ImagePlane A = Video::Renderer::A; |
| 18 | +static constexpr Video::Renderer::ImagePlane B = Video::Renderer::B; |
| 19 | + |
| 20 | +template<typename RENDERER, Video::Renderer::BitsPerPixel BPS, Video::ImageCodingMethod CODINGA, Video::ImageCodingMethod CODINGB> |
| 21 | +static void benchmarkRenderer(std::string_view name) |
| 22 | +{ |
| 23 | + RENDERER renderer; |
| 24 | + renderer.m_codingMethod[A] = CODINGA; |
| 25 | + renderer.m_codingMethod[B] = CODINGB; |
| 26 | + renderer.m_bps[A] = BPS; |
| 27 | + renderer.m_bps[B] = BPS; |
| 28 | + renderer.SetDisplayFormat(Video::Renderer::DisplayFormat::PAL, false, false); |
| 29 | + renderer.m_mix = true; |
| 30 | + |
| 31 | + uint16_t lineNumber = 0; |
| 32 | + |
| 33 | + // Benchmark |
| 34 | + const std::chrono::high_resolution_clock::time_point start = std::chrono::high_resolution_clock::now(); |
| 35 | + for(size_t f = 0; f < FRAMES; ++f) |
| 36 | + { |
| 37 | + for(size_t y = 0; y < HEIGHT; ++y) |
| 38 | + { |
| 39 | + renderer.DrawLine(LINEA.data(), LINEB.data(), lineNumber++); |
| 40 | + } |
| 41 | + lineNumber = 0; |
| 42 | + renderer.RenderFrame(); |
| 43 | + } |
| 44 | + const std::chrono::high_resolution_clock::time_point finish = std::chrono::high_resolution_clock::now(); |
| 45 | + const std::chrono::nanoseconds delta = finish - start; |
| 46 | + |
| 47 | + std::println("{} {} {} {}/f {}", |
| 48 | + name, |
| 49 | + delta, |
| 50 | + std::chrono::duration_cast<std::chrono::microseconds>(delta), |
| 51 | + std::chrono::duration_cast<std::chrono::microseconds>(delta / FRAMES), |
| 52 | + std::chrono::duration_cast<std::chrono::milliseconds>(delta) |
| 53 | + ); |
| 54 | +} |
| 55 | + |
| 56 | +template<typename RENDERER> |
| 57 | +static void benchmarkRendererCursor(std::string_view name) |
| 58 | +{ |
| 59 | + RENDERER renderer; |
| 60 | + renderer.SetCursorEnabled(true); |
| 61 | + renderer.SetDisplayFormat(Video::Renderer::DisplayFormat::PAL, false, false); |
| 62 | + |
| 63 | + // Benchmark |
| 64 | + const std::chrono::high_resolution_clock::time_point start = std::chrono::high_resolution_clock::now(); |
| 65 | + for(size_t f = 0; f < FRAMES_CURSOR; ++f) |
| 66 | + { |
| 67 | + renderer.RenderFrame(); |
| 68 | + } |
| 69 | + const std::chrono::high_resolution_clock::time_point finish = std::chrono::high_resolution_clock::now(); |
| 70 | + const std::chrono::nanoseconds delta = finish - start; |
| 71 | + |
| 72 | + std::println("{} {} {} {}/f {}", |
| 73 | + name, |
| 74 | + delta, |
| 75 | + std::chrono::duration_cast<std::chrono::microseconds>(delta), |
| 76 | + delta / FRAMES_CURSOR, |
| 77 | + std::chrono::duration_cast<std::chrono::milliseconds>(delta) |
| 78 | + ); |
| 79 | +} |
| 80 | + |
| 81 | +int main() |
| 82 | +{ |
| 83 | + constexpr Video::Renderer::BitsPerPixel NORMAL_8 = Video::Renderer::BitsPerPixel::Normal8; |
| 84 | + constexpr Video::Renderer::BitsPerPixel DOUBLE_4 = Video::Renderer::BitsPerPixel::Double4; |
| 85 | + // constexpr Video::Renderer::BitsPerPixel HIGH_8 = Video::Renderer::BitsPerPixel::High8; |
| 86 | + |
| 87 | + benchmarkRendererCursor<Video::RendererSoftware>("Cursor Soft"); |
| 88 | + benchmarkRendererCursor<Video::RendererSIMD>("Cursor SIMD"); |
| 89 | + |
| 90 | + benchmarkRenderer<Video::RendererSoftware, NORMAL_8, ICM(OFF), ICM(RGB555)>("Normal Soft RGB555"); |
| 91 | + benchmarkRenderer<Video::RendererSIMD, NORMAL_8, ICM(OFF), ICM(RGB555)>("Normal SIMD RGB555"); |
| 92 | + |
| 93 | + benchmarkRenderer<Video::RendererSoftware, NORMAL_8, ICM(DYUV), ICM(DYUV)>("Normal Soft DYUV"); |
| 94 | + benchmarkRenderer<Video::RendererSIMD, NORMAL_8, ICM(DYUV), ICM(DYUV)>("Normal SIMD DYUV"); |
| 95 | + |
| 96 | + benchmarkRenderer<Video::RendererSoftware, DOUBLE_4, ICM(DYUV), ICM(DYUV)>("Double Soft DYUV"); |
| 97 | + benchmarkRenderer<Video::RendererSIMD, DOUBLE_4, ICM(DYUV), ICM(DYUV)>("Double SIMD DYUV"); |
| 98 | + |
| 99 | + benchmarkRenderer<Video::RendererSoftware, DOUBLE_4, ICM(CLUT4), ICM(CLUT4)>("Double Soft CLUT4"); |
| 100 | + benchmarkRenderer<Video::RendererSIMD, DOUBLE_4, ICM(CLUT4), ICM(CLUT4)>("Double SIMD CLUT4"); |
| 101 | + |
| 102 | + benchmarkRenderer<Video::RendererSoftware, NORMAL_8, ICM(CLUT8), ICM(CLUT7)>("Normal Soft CLUT8/CLUT7"); |
| 103 | + benchmarkRenderer<Video::RendererSIMD, NORMAL_8, ICM(CLUT8), ICM(CLUT7)>("Normal SIMD CLUT8/CLUT7"); |
| 104 | + |
| 105 | + benchmarkRenderer<Video::RendererSoftware, DOUBLE_4, ICM(CLUT8), ICM(CLUT7)>("Double Soft CLUT8/CLUT7"); |
| 106 | + benchmarkRenderer<Video::RendererSIMD, DOUBLE_4, ICM(CLUT8), ICM(CLUT7)>("Double SIMD CLUT8/CLUT7"); |
| 107 | +} |
0 commit comments