aboutsummaryrefslogtreecommitdiffstats
path: root/tests/entityXTests.cpp
blob: 2f814c5191cfef71d2296f244aae82c6217cc3c7 (plain)
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#include <string>
#include <vector>
#include <thread>
#include <memory>

#define BENCHPRESS_CONFIG_MAIN
#include "benchpress.hpp"

#include <entityx/entityx.h>

#include "EntityXBenchmark.h"

inline void init_entities(entityx::EntityManager& entities, size_t nentities){
    for (size_t i = 0; i < nentities; i++) {
		auto entity = entities.create();

		entity.assign<EntityXBenchmark::PositionComponent>();
		entity.assign<EntityXBenchmark::DirectionComponent>();

		if (i % 2) {
			entity.assign<EntityXBenchmark::ComflabulationComponent>();
		}
	}
}

inline void runEntitiesSystemsEntityXBenchmark(benchpress::context* ctx, size_t nentities) {
    EntityXBenchmark::Application app;
    auto& entities = app.entities;

    init_entities(entities, nentities);

    ctx->reset_timer();
    for (size_t i = 0; i < ctx->num_iterations(); ++i) {
        app.update(EntityXBenchmark::fakeDeltaTime);
    }
}




BENCHMARK("entityx create destroy entity with components", [](benchpress::context* ctx) {
    entityx::EntityX app;
    auto& entities = app.entities;

    ctx->reset_timer();
    for (size_t i = 0; i < ctx->num_iterations(); ++i) {
        auto entity = entities.create();

        entity.assign<EntityXBenchmark::PositionComponent>();
		entity.assign<EntityXBenchmark::DirectionComponent>();
		entity.assign<EntityXBenchmark::ComflabulationComponent>();

        entity.destroy();
    }
})





class BenchmarksEntityX {
    public:
    static const std::vector<int> ENTITIES;

    static inline void makeBenchmarks(std::string name) {
        makeBenchmarks(name, ENTITIES);
    }
    
    static void makeBenchmarks(std::string name, const std::vector<int>& entities) {
        for(int nentities : entities) {
            std::string tag = "[" + std::to_string(nentities) + "]";

            std::stringstream ss;
            ss << std::right << std::setw(10) << tag << ' ';
            ss << name << ' ';
            ss << std::right << std::setw(8) << nentities;
            ss << " entities component systems update";

            std::string benchmark_name = ss.str();
            BENCHMARK(benchmark_name, [nentities](benchpress::context* ctx) {
                runEntitiesSystemsEntityXBenchmark(ctx, nentities);
            })
        }
    }

    BenchmarksEntityX(std::string name){
        makeBenchmarks(name);
    }
};
const std::vector<int> BenchmarksEntityX::ENTITIES = {
    25, 50, 
    100, 200, 400, 800, 
    1600, 3200, 5000, 
    10'000, 30'000, 
    100'000, 500'000, 
    1'000'000, 2'000'000
};

BenchmarksEntityX entityxbenchmarks ("entityx");





/*
BENCHMARK("[25]     entityx      25 entities component systems update", [](benchpress::context* ctx) {
    runEntitiesSystemsEntityXBenchmark(ctx, 25);
})

BENCHMARK("[50]     entityx      50 entities component systems update", [](benchpress::context* ctx) {
    runEntitiesSystemsEntityXBenchmark(ctx, 50);
})

BENCHMARK("[100]    entityx     100 entities component systems update", [](benchpress::context* ctx) {
    runEntitiesSystemsEntityXBenchmark(ctx, 100);
})

BENCHMARK("[200]    entityx     200 entities component systems update", [](benchpress::context* ctx) {
    runEntitiesSystemsEntityXBenchmark(ctx, 200);
})


BENCHMARK("[400]    entityx     400 entities component systems update", [](benchpress::context* ctx) {
    runEntitiesSystemsEntityXBenchmark(ctx, 400);
})


BENCHMARK("[800]    entityx     800 entities component systems update", [](benchpress::context* ctx) {
    runEntitiesSystemsEntityXBenchmark(ctx, 800);
})


BENCHMARK("[1600]    entityx   1600 entities component systems update", [](benchpress::context* ctx) {
    runEntitiesSystemsEntityXBenchmark(ctx, 1600);
})



BENCHMARK("[3200]    entityx   3200 entities component systems update", [](benchpress::context* ctx) {
    runEntitiesSystemsEntityXBenchmark(ctx, 3200);
})


BENCHMARK("[5000]    entityx   5000 entities component systems update", [](benchpress::context* ctx) {
    runEntitiesSystemsEntityXBenchmark(ctx, 5000);
})


BENCHMARK("[10000]   entityx  10000 entities component systems update", [](benchpress::context* ctx) {
    runEntitiesSystemsEntityXBenchmark(ctx, 10'000);
})

BENCHMARK("[30000]   entityx  30000 entities component systems update", [](benchpress::context* ctx) {
    runEntitiesSystemsEntityXBenchmark(ctx, 30'000);
})


BENCHMARK("[100000]  entityx 100000 entities component systems update", [](benchpress::context* ctx) {
    runEntitiesSystemsEntityXBenchmark(ctx, 100'000L);
})


BENCHMARK("[500000]  entityx 500000 entities component systems update", [](benchpress::context* ctx) {
    runEntitiesSystemsEntityXBenchmark(ctx, 500'000L);
})

BENCHMARK("[1000000] entityx     1M entities component systems update", [](benchpress::context* ctx) {
    runEntitiesSystemsEntityXBenchmark(ctx, 1'000'000L);
})

BENCHMARK("[2000000] entityx     2M entities component systems update", [](benchpress::context* ctx) {
    runEntitiesSystemsEntityXBenchmark(ctx, 2'000'000L);
})
*/