-
Notifications
You must be signed in to change notification settings - Fork 11
/
benchmark.cpp
91 lines (85 loc) · 2.24 KB
/
benchmark.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#if !NDEBUG
static_assert(false, "Running in debug move");
#endif
#include <entityplus/entity.h>
#include <entityx/entityx.h>
#include <chrono>
#include <iostream>
class Timer {
std::chrono::high_resolution_clock::time_point start;
const char *str;
public:
Timer(const char *str): start(std::chrono::high_resolution_clock::now()),
str(str) {}
~Timer() {
auto end = std::chrono::high_resolution_clock::now();
std::cout << str << std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() << "\n";
}
};
void entPlusTest(int entityCount, int iterationCount, int tagProb) {
using namespace entityplus;
entity_manager<component_list<int>, tag_list<struct Tag>> em;
em.create_grouping<int, Tag>();
std::cout << "EntityPlus\n";
{
Timer timer("Add entities: ");
for (int i = 0; i < entityCount; ++i) {
auto ent = em.create_entity();
ent.add_component<int>(i);
if (i % tagProb == 0)
ent.set_tag<Tag>(true);
}
}
{
Timer timer("For_each entities: ");
std::uint64_t sum = 0;
for (int i = 0; i < iterationCount; ++i) {
em.for_each<Tag, int>([&](auto ent, auto i) {
sum += i;
});
}
std::cout << sum << "\n";
}
}
void entXTest(int entityCount, int iterationCount, int tagProb) {
using namespace entityx;
struct Tag {};
entityx::EntityX ex;
std::cout << "EntityX\n";
{
Timer timer("Add entities: ");
for (int i = 0; i < entityCount; ++i) {
auto ent = ex.entities.create();
ent.assign<int>(i);
if (i % tagProb == 0)
ent.assign<Tag>();
}
}
{
Timer timer("For_each entities: ");
std::uint64_t sum = 0;
for (int i = 0; i < iterationCount; ++i) {
ex.entities.each<Tag, int>([&](auto ent, auto &, auto i) {
sum += i;
});
}
std::cout << sum << "\n";
}
}
void runTest(int entityCount, int iterationCount, int tagProb) {
std::cout << "Count: " << entityCount
<< " ItrCount: " << iterationCount
<< " TagProb: " << tagProb << "\n";
entPlusTest(entityCount, iterationCount, tagProb);
//std::cout << "\n";
//entXTest(entityCount, iterationCount, tagProb);
std::cout << "\n\n";
}
int main() {
runTest(1'000, 1'000'000, 3);
runTest(10'000, 1'000'000, 3);
runTest(30'000, 100'000, 3);
runTest(100'000, 100'000, 5);
runTest(10'000, 1'000'000, 1'000);
runTest(100'000, 1'000'000, 1'000);
}