[Chore] (MG_Benchmark): add benchmark

This commit is contained in:
2025-08-06 13:25:24 +08:00
parent 2c651f2359
commit 3606b80016
2 changed files with 56 additions and 0 deletions
+25
View File
@@ -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
)
+31
View File
@@ -0,0 +1,31 @@
#include <benchmark/benchmark.h>
#include <vector>
static void Sanity_VectorResize(benchmark::State& state) {
for (auto _ : state) {
std::vector<int> 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();