Changes from before AGS where I was adding Lua perf tests but not magic_stats yet.

master
Zed A. Shaw 1 week ago
parent 89c3848a1b
commit b429ee47d8
  1. 5
      Makefile
  2. 1
      meson.build
  3. 150
      tests/data.hpp
  4. 136
      tests/lua_perf_tests.cpp
  5. 2
      tests/main.cpp
  6. 178
      tests/perf_tests.cpp
  7. 2
      tests/soa_tests.cpp

@ -1,4 +1,4 @@
all: build test all: build test_perf
reset: reset:
ifeq '$(OS)' 'Windows_NT' ifeq '$(OS)' 'Windows_NT'
@ -18,6 +18,9 @@ debug_build:
meson setup --wipe builddir -Db_ndebug=true --buildtype debugoptimized meson setup --wipe builddir -Db_ndebug=true --buildtype debugoptimized
meson compile -j 10 -C builddir meson compile -j 10 -C builddir
test_perf: build
./builddir/sol2_test -m "perf"
test: build test: build
./builddir/sol2_test ./builddir/sol2_test

@ -32,6 +32,7 @@ executable('sol2_test', [
'tests/bao_tests.cpp', 'tests/bao_tests.cpp',
'tests/soa_tests.cpp', 'tests/soa_tests.cpp',
'tests/perf_tests.cpp', 'tests/perf_tests.cpp',
'tests/lua_perf_tests.cpp',
'src/stats.cpp', 'src/stats.cpp',
'tests/main.cpp', 'tests/main.cpp',
], ],

@ -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),
}
};
}

@ -4,6 +4,7 @@ TEST_SET(sol2_tests);
TEST_SET(bao_tests); TEST_SET(bao_tests);
TEST_SET(soa_tests); TEST_SET(soa_tests);
TEST_SET(perf_tests); TEST_SET(perf_tests);
TEST_SET(lua_perf_tests);
using namespace fuc2; using namespace fuc2;
@ -13,6 +14,7 @@ int main(int argc, char* argv[]) {
bao_tests::TESTS, bao_tests::TESTS,
soa_tests::TESTS, soa_tests::TESTS,
perf_tests::TESTS, perf_tests::TESTS,
lua_perf_tests::TESTS,
}; };
return run_tests(tests, argc, argv); return run_tests(tests, argc, argv);

@ -2,159 +2,11 @@
#include <string> #include <string>
#include <fuc2/testing.hpp> #include <fuc2/testing.hpp>
#include "stats.hpp" #include "stats.hpp"
#include "data.hpp"
using namespace fuc2; using namespace fuc2;
namespace perf_tests { namespace perf_tests {
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});
}
};
struct Samples { struct Samples {
std::vector<Stats> soa_big_for; std::vector<Stats> soa_big_for;
std::vector<Stats> soa_many_for; std::vector<Stats> soa_many_for;
@ -431,7 +283,7 @@ namespace perf_tests {
int sample_size = 100; int sample_size = 100;
int sample_count = 100; int sample_count = 100;
for(int i = 0; i < 100; i++) { for(int i = 0; i < 10; i++) {
// quick and dirty "randomness" // quick and dirty "randomness"
if(i % 2 == 0) { if(i % 2 == 0) {
test_large_soa(samples, sample_size, sample_count); test_large_soa(samples, sample_size, sample_count);
@ -480,24 +332,32 @@ namespace perf_tests {
maos_many_for_2.sample(samples.maos_many_for_2[i].mean()); maos_many_for_2.sample(samples.maos_many_for_2[i].mean());
} }
soa_big_for.dump("soa_big_for");
soa_many_for.dump("soa_many_for");
ls_big_for.dump("ls_big_for");
ls_many_for.dump("ls_many_for");
maos_big_for.dump("maos_big_for");
maos_many_for.dump("maos_many_for");
maos_many_for_2.dump("maos_many_for_2");
// totally not sure if this t-test is legit, must study more // totally not sure if this t-test is legit, must study more
soa_big_for.t_test(ls_big_for); soa_big_for.t_test(ls_big_for);
soa_big_for.t_test(maos_big_for); soa_big_for.t_test(maos_big_for);
soa_many_for.t_test(ls_many_for); // soa_many_for.t_test(ls_many_for);
soa_many_for.t_test(maos_many_for); // soa_many_for.t_test(maos_many_for);
ls_many_for.t_test(maos_many_for); // ls_many_for.t_test(maos_many_for);
ls_big_for.t_test(maos_big_for); // ls_big_for.t_test(maos_big_for);
// the most pathologic case // // the most pathologic case
fmt::println("---- {}", soa_big_for.mean() - ls_many_for.mean()); // fmt::println("---- {}", soa_big_for.mean() - ls_many_for.mean());
soa_big_for.t_test(ls_many_for); // soa_big_for.t_test(ls_many_for);
fmt::println("--- MAOS many_for vs many_for_2"); // fmt::println("--- MAOS many_for vs many_for_2");
maos_many_for.t_test(maos_many_for_2); maos_many_for.t_test(maos_many_for_2);
fmt::println("--- MAOS big_for vs many_for_2"); // fmt::println("--- MAOS big_for vs many_for_2");
maos_big_for.t_test(maos_many_for_2); maos_big_for.t_test(maos_many_for_2);
} }

@ -10,8 +10,6 @@ using namespace fuc2;
namespace soa_tests { namespace soa_tests {
struct SOAStyle { struct SOAStyle {
std::vector<std::string> name; std::vector<std::string> name;
std::vector<int> hp; std::vector<int> hp;

Loading…
Cancel
Save