diff --git a/MobileGL/MG_Benchmark/CMakeLists.txt b/MobileGL/MG_Benchmark/CMakeLists.txt new file mode 100644 index 00000000..7eb3e71e --- /dev/null +++ b/MobileGL/MG_Benchmark/CMakeLists.txt @@ -0,0 +1,25 @@ +cmake_minimum_required(VERSION 3.14) +project(MobileGLTest) + +set(CMAKE_CXX_STANDARD 23) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + + +include(FetchContent) +FetchContent_Declare( + benchmark + GIT_REPOSITORY https://github.com/google/benchmark.git + GIT_TAG v1.9.4 +) +FetchContent_MakeAvailable(benchmark) + +set(MGL_ROOT ${CMAKE_CURRENT_LIST_DIR}/../..) + +add_executable( + SanityBench + SanityBench.cpp +) +target_link_libraries( + SanityBench + benchmark::benchmark +) diff --git a/MobileGL/MG_Benchmark/SanityBench.cpp b/MobileGL/MG_Benchmark/SanityBench.cpp new file mode 100644 index 00000000..cb0a49f3 --- /dev/null +++ b/MobileGL/MG_Benchmark/SanityBench.cpp @@ -0,0 +1,31 @@ +#include +#include + +static void Sanity_VectorResize(benchmark::State& state) { + for (auto _ : state) { + std::vector v; + v.resize(state.range(0), 0); + for (int i = 0; i < state.range(0); i += 16) { + v[i] = i; + } + } + state.SetBytesProcessed(int64_t(state.iterations()) * + int64_t(state.range(0))); +} +BENCHMARK(Sanity_VectorResize)->Arg(2<<5)->Arg(2<<10)->Arg(2<<20); + + +static void Sanity_memcpy(benchmark::State& state) { + char* src = new char[state.range(0)]; + char* dst = new char[state.range(0)]; + memset(src, 'x', state.range(0)); + for (auto _ : state) + memcpy(dst, src, state.range(0)); + state.SetBytesProcessed(int64_t(state.iterations()) * + int64_t(state.range(0))); + delete[] src; + delete[] dst; +} +BENCHMARK(Sanity_memcpy)->Range(8, 8<<10); + +BENCHMARK_MAIN(); \ No newline at end of file