50 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			50 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
#include "refl/vertex.h"
 | 
						|
#include <benchmark/benchmark.h>
 | 
						|
auto cls = &TypeInfo<vec3>::StaticClass;
 | 
						|
vec3 v;
 | 
						|
auto ov = cls->New((void*)&v);
 | 
						|
void TestRefl1(benchmark::State& state) {
 | 
						|
	int x = 1, y = 2;
 | 
						|
	auto f = cls->GetField(GetStaticFieldID<vec3_Meta>(FName("name")));
 | 
						|
	string hello;
 | 
						|
	ov.Get(FName("name"), hello);
 | 
						|
	hello = *f->data.member.value.CastTo<string*>();
 | 
						|
	ov.Set(FName("name"), hello);
 | 
						|
	constexpr auto r = StaticMemberField(&vec3::name, FName("name"), { ("hello meta")});
 | 
						|
	for (auto _ : state) {
 | 
						|
		std::array<Any, 4> arr{&x, ov.ptr};
 | 
						|
		svector<Any> svec(arr, 2);
 | 
						|
		ov.Invoke(FName("norm"), svec);
 | 
						|
	}
 | 
						|
}
 | 
						|
BENCHMARK(TestRefl1);
 | 
						|
void TestRefl2(benchmark::State& state) {
 | 
						|
	int x = 1, y = 2;
 | 
						|
	constexpr auto id = GetStaticFieldID<vec3_Meta>(FName("norm"));
 | 
						|
	auto field = cls->GetField(id);
 | 
						|
	for (auto _ : state) {
 | 
						|
		std::array<Any, 4> arr{&x, ov.ptr};
 | 
						|
		svector<Any> svec(arr, 2);
 | 
						|
		field->Invoke(svec);
 | 
						|
	}
 | 
						|
}
 | 
						|
BENCHMARK(TestRefl2);
 | 
						|
void TestRefl3(benchmark::State& state) {
 | 
						|
	int x = 1, y = 2;
 | 
						|
	constexpr auto id = GetStaticFieldID<vec3_Meta>(FName("norm"));
 | 
						|
	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();
 |