parent
89c3848a1b
commit
b429ee47d8
@ -0,0 +1,150 @@ |
|||||||
|
#pragma once |
||||||
|
|
||||||
|
struct LargeSOA { |
||||||
|
std::vector<int> a01; |
||||||
|
std::vector<int> a02; |
||||||
|
std::vector<int> a03; |
||||||
|
std::vector<int> a04; |
||||||
|
std::vector<int> a05; |
||||||
|
std::vector<int> a06; |
||||||
|
std::vector<int> a07; |
||||||
|
std::vector<int> a08; |
||||||
|
std::vector<int> a09; |
||||||
|
std::vector<int> a10; |
||||||
|
std::vector<int> a11; |
||||||
|
std::vector<int> a12; |
||||||
|
std::vector<int> a13; |
||||||
|
std::vector<int> a14; |
||||||
|
std::vector<int> a15; |
||||||
|
std::vector<int> a16; |
||||||
|
std::vector<int> a17; |
||||||
|
std::vector<int> a18; |
||||||
|
std::vector<int> a19; |
||||||
|
std::vector<int> a20; |
||||||
|
|
||||||
|
void push_back(int x) { |
||||||
|
a01.push_back(x); |
||||||
|
a02.push_back(x); |
||||||
|
a03.push_back(x); |
||||||
|
a04.push_back(x); |
||||||
|
a05.push_back(x); |
||||||
|
a06.push_back(x); |
||||||
|
a07.push_back(x); |
||||||
|
a08.push_back(x); |
||||||
|
a09.push_back(x); |
||||||
|
a10.push_back(x); |
||||||
|
a11.push_back(x); |
||||||
|
a12.push_back(x); |
||||||
|
a13.push_back(x); |
||||||
|
a14.push_back(x); |
||||||
|
a15.push_back(x); |
||||||
|
a16.push_back(x); |
||||||
|
a17.push_back(x); |
||||||
|
a18.push_back(x); |
||||||
|
a19.push_back(x); |
||||||
|
a20.push_back(x); |
||||||
|
} |
||||||
|
}; |
||||||
|
|
||||||
|
struct LargeStruct { |
||||||
|
int a01; |
||||||
|
int a02; |
||||||
|
int a03; |
||||||
|
int a04; |
||||||
|
int a05; |
||||||
|
int a06; |
||||||
|
int a07; |
||||||
|
int a08; |
||||||
|
int a09; |
||||||
|
int a10; |
||||||
|
int a11; |
||||||
|
int a12; |
||||||
|
int a13; |
||||||
|
int a14; |
||||||
|
int a15; |
||||||
|
int a16; |
||||||
|
int a17; |
||||||
|
int a18; |
||||||
|
int a19; |
||||||
|
int a20; |
||||||
|
|
||||||
|
LargeStruct(int x) : |
||||||
|
a01(x), |
||||||
|
a02(x), |
||||||
|
a03(x), |
||||||
|
a04(x), |
||||||
|
a05(x), |
||||||
|
a06(x), |
||||||
|
a07(x), |
||||||
|
a08(x), |
||||||
|
a09(x), |
||||||
|
a10(x), |
||||||
|
a11(x), |
||||||
|
a12(x), |
||||||
|
a13(x), |
||||||
|
a14(x), |
||||||
|
a15(x), |
||||||
|
a16(x), |
||||||
|
a17(x), |
||||||
|
a18(x), |
||||||
|
a19(x), |
||||||
|
a20(x) {} |
||||||
|
}; |
||||||
|
|
||||||
|
|
||||||
|
struct S1 { |
||||||
|
int a01; |
||||||
|
int a02; |
||||||
|
int a03; |
||||||
|
int a04; |
||||||
|
|
||||||
|
S1(int x) : a01(x), a02(x), a03(x), a04(x) { } |
||||||
|
}; |
||||||
|
|
||||||
|
struct S2 { |
||||||
|
int a05; |
||||||
|
int a06; |
||||||
|
int a07; |
||||||
|
int a08; |
||||||
|
S2(int x) : a05(x), a06(x), a07(x), a08(x) { } |
||||||
|
}; |
||||||
|
|
||||||
|
struct S3 { |
||||||
|
int a09; |
||||||
|
int a10; |
||||||
|
int a11; |
||||||
|
int a12; |
||||||
|
S3(int x) : a09(x), a10(x), a11(x), a12(x) { } |
||||||
|
}; |
||||||
|
|
||||||
|
struct S4 { |
||||||
|
int a13; |
||||||
|
int a14; |
||||||
|
int a15; |
||||||
|
int a16; |
||||||
|
S4(int x) : a13(x), a14(x), a15(x), a16(x) { } |
||||||
|
}; |
||||||
|
|
||||||
|
struct S5 { |
||||||
|
int a17; |
||||||
|
int a18; |
||||||
|
int a19; |
||||||
|
int a20; |
||||||
|
S5(int x) : a17(x), a18(x), a19(x), a20(x) { } |
||||||
|
}; |
||||||
|
|
||||||
|
struct MultipleAOS { |
||||||
|
std::vector<S1> s1; |
||||||
|
std::vector<S2> s2; |
||||||
|
std::vector<S3> s3; |
||||||
|
std::vector<S4> s4; |
||||||
|
std::vector<S5> s5; |
||||||
|
|
||||||
|
void push_back(int x) { |
||||||
|
s1.push_back({x}); |
||||||
|
s2.push_back({x}); |
||||||
|
s3.push_back({x}); |
||||||
|
s4.push_back({x}); |
||||||
|
s5.push_back({x}); |
||||||
|
} |
||||||
|
}; |
||||||
@ -0,0 +1,136 @@ |
|||||||
|
#include <fmt/core.h> |
||||||
|
#include <string> |
||||||
|
#include <fuc2/testing.hpp> |
||||||
|
#include "stats.hpp" |
||||||
|
#include "data.hpp" |
||||||
|
#define SOL_ALL_SAFETIES_ON 1 |
||||||
|
#include <sol/sol.hpp> |
||||||
|
|
||||||
|
using namespace fuc2; |
||||||
|
|
||||||
|
namespace lua_perf_tests { |
||||||
|
struct Samples { |
||||||
|
std::vector<Stats> maos_many_for; |
||||||
|
std::vector<Stats> lua_many_for; |
||||||
|
}; |
||||||
|
|
||||||
|
void test_maos_performance(Samples& samples, int sample_size, int sample_number) { |
||||||
|
auto maos = new MultipleAOS(); |
||||||
|
|
||||||
|
for(int i = 0; i < sample_size; i++) { |
||||||
|
maos->push_back(i); |
||||||
|
} |
||||||
|
|
||||||
|
Stats maos_many_for; |
||||||
|
for(int sample = 0; sample < sample_number; sample++) { |
||||||
|
auto start = maos_many_for.time_start(); |
||||||
|
|
||||||
|
for(auto& el : maos->s1) { |
||||||
|
el.a01 += el.a02 + sample; |
||||||
|
el.a02 += el.a03 + sample; |
||||||
|
el.a03 += el.a04 + sample; |
||||||
|
} |
||||||
|
|
||||||
|
for(auto& el : maos->s2) { |
||||||
|
el.a05 += el.a06 + sample; |
||||||
|
el.a06 += el.a07 + sample; |
||||||
|
el.a07 += el.a08 + sample; |
||||||
|
} |
||||||
|
|
||||||
|
for(auto& el : maos->s3) { |
||||||
|
el.a09 += el.a10 + sample; |
||||||
|
el.a10 += el.a11 + sample; |
||||||
|
el.a11 += el.a12 + sample; |
||||||
|
} |
||||||
|
|
||||||
|
for(auto& el : maos->s4) { |
||||||
|
el.a13 += el.a14 + sample; |
||||||
|
el.a14 += el.a15 + sample; |
||||||
|
el.a15 += el.a16 + sample; |
||||||
|
} |
||||||
|
|
||||||
|
for(auto& el : maos->s5) { |
||||||
|
el.a17 += el.a18 + sample; |
||||||
|
el.a18 += el.a19 + sample; |
||||||
|
el.a19 += el.a20 + sample; |
||||||
|
} |
||||||
|
|
||||||
|
maos_many_for.sample_time(start); |
||||||
|
} |
||||||
|
|
||||||
|
samples.maos_many_for.push_back(maos_many_for); |
||||||
|
} |
||||||
|
|
||||||
|
void test_lua_maos_perf(Samples& samples, int sample_size, int sample_number) { |
||||||
|
sol::state lua; |
||||||
|
lua.open_libraries(sol::lib::base); |
||||||
|
|
||||||
|
auto maos = new MultipleAOS(); |
||||||
|
|
||||||
|
for(int i = 0; i < sample_size; i++) { |
||||||
|
maos->push_back(i); |
||||||
|
} |
||||||
|
|
||||||
|
// setup lua for MOAS
|
||||||
|
lua.new_usertype<S1>("S1", |
||||||
|
"a01", &S1::a01, |
||||||
|
"a02", &S1::a02, |
||||||
|
"a03", &S1::a03, |
||||||
|
"a04", &S1::a04); |
||||||
|
|
||||||
|
lua.script(R"( |
||||||
|
function effed_handler(v, size, sample) |
||||||
|
for i = 1,size,1 do |
||||||
|
v[i].a01 = v[i].a01 + v[i].a02 + sample |
||||||
|
v[i].a02 = v[i].a02 + v[i].a03 + sample |
||||||
|
v[i].a03 = v[i].a03 + v[i].a04 + sample |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
function handler(v, sample) |
||||||
|
v.a01 = v.a01 + v.a02 + sample |
||||||
|
v.a02 = v.a02 + v.a03 + sample |
||||||
|
v.a03 = v.a03 + v.a04 + sample |
||||||
|
end |
||||||
|
)"); |
||||||
|
|
||||||
|
sol::function handler = lua["handler"]; |
||||||
|
|
||||||
|
Stats lua_many_for; |
||||||
|
for(int sample = 0; sample < sample_number; sample++) { |
||||||
|
auto start = lua_many_for.time_start(); |
||||||
|
|
||||||
|
for(auto& el : maos->s1) { |
||||||
|
handler(el, sample); |
||||||
|
} |
||||||
|
|
||||||
|
lua_many_for.sample_time(start); |
||||||
|
} |
||||||
|
|
||||||
|
samples.lua_many_for.push_back(lua_many_for); |
||||||
|
} |
||||||
|
|
||||||
|
void test_all_performance() { |
||||||
|
Samples samples; |
||||||
|
int sample_size = 100; |
||||||
|
int sample_count = 100; |
||||||
|
|
||||||
|
for(int i = 0; i < 10; i++) { |
||||||
|
test_maos_performance(samples, sample_size, sample_count); |
||||||
|
test_lua_maos_perf(samples, sample_size, sample_count); |
||||||
|
} |
||||||
|
|
||||||
|
for(size_t i = 0; i < samples.maos_many_for.size(); i++) { |
||||||
|
fmt::println("{:.2f} {:.2f}", |
||||||
|
samples.maos_many_for[i].mean(), |
||||||
|
samples.lua_many_for[i].mean()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
fuc2::Set TESTS{ |
||||||
|
.name="lua_perf", |
||||||
|
.tests={ |
||||||
|
TEST(test_all_performance), |
||||||
|
} |
||||||
|
}; |
||||||
|
} |
||||||
Loading…
Reference in new issue