zengine-old/engine/3rdparty/zlib/test/refl_01.cpp
2024-04-16 16:17:13 +08:00

45 lines
1.1 KiB
C++

#include "refl/vertex.h"
#include <benchmark/benchmark.h>
auto cls = &TypeInfo<vec3>::StaticClass;
vec3 v;
auto ov = cls->New((void*)&v);
constexpr Name func("norm");
void TestRefl1(benchmark::State& state) {
int x = 1, y = 2;
for (auto _ : state) {
std::array<ArgsView, 4> arr{&x, ov.ptr};
svector<ArgsView> svec(&arr.front(), arr.size(), 2);
ov.Invoke("norm", svec);
}
}
BENCHMARK(TestRefl1);
void TestRefl2(benchmark::State& state) {
int x = 1, y = 2;
constexpr auto id = GetStaticFieldID<vec3>(func);
auto field = cls->GetField(id);
for (auto _ : state) {
std::array<ArgsView, 4> arr{&x, ov.ptr};
svector<ArgsView> svec(&arr.front(), arr.size(), 2);
field->Invoke(svec);
}
}
BENCHMARK(TestRefl2);
void TestRefl3(benchmark::State& state) {
int x = 1, y = 2;
constexpr auto id = GetStaticFieldID<vec3>(func);
auto field = cls->GetField(id);
for (auto _ : state) {
field->Invoke({ &x,ov.ptr, x, y });
}
}
BENCHMARK(TestRefl3);
void TestCPlusPlus(benchmark::State& state) {
int x = 1, y = 2;
for (auto _ : state) {
x = v.norm(x, y);
}
}
BENCHMARK(TestCPlusPlus);
BENCHMARK_MAIN();