2024-04-11 10:13:15 +08:00
|
|
|
#include "refl/vertex.h"
|
|
|
|
|
#include <benchmark/benchmark.h>
|
|
|
|
|
void TestRefl1(benchmark::State& state) {
|
|
|
|
|
auto cls = &TypeInfo<vec3>::StaticClass;
|
|
|
|
|
vec3 v;
|
|
|
|
|
auto ptr = (void*)&v;
|
|
|
|
|
auto ov = cls->New(ptr);
|
|
|
|
|
int x = 1, y = 2;
|
|
|
|
|
for (auto _ : state) {
|
|
|
|
|
ov.Invoke("norm", { {},ptr, x, y});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
BENCHMARK(TestRefl1);
|
|
|
|
|
void TestRefl2(benchmark::State& state) {
|
|
|
|
|
auto cls = &TypeInfo<vec3>::StaticClass;
|
|
|
|
|
vec3 v;
|
|
|
|
|
auto ptr = (void*)&v;
|
|
|
|
|
auto ov = cls->New(ptr);
|
|
|
|
|
int x = 1, y = 2;
|
|
|
|
|
std::vector<ArgsView> ArgsList;
|
|
|
|
|
ArgsList.emplace_back();
|
|
|
|
|
ArgsList.emplace_back(ptr);
|
|
|
|
|
ArgsList.emplace_back(x);
|
|
|
|
|
ArgsList.emplace_back(y);
|
|
|
|
|
auto field = cls->GetField(cls, "norm", true);
|
|
|
|
|
for (auto _ : state) {
|
|
|
|
|
field->Invoke(ArgsList);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
BENCHMARK(TestRefl2);
|
|
|
|
|
void TestCPlusPlus(benchmark::State& state) {
|
|
|
|
|
vec3 v;
|
|
|
|
|
int x = 1, y = 2;
|
|
|
|
|
for (auto _ : state) {
|
|
|
|
|
v.norm(x, y);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
BENCHMARK(TestCPlusPlus);
|
2024-04-09 22:26:33 +08:00
|
|
|
|
2024-04-11 10:13:15 +08:00
|
|
|
BENCHMARK_MAIN();
|