Last active
April 1, 2022 20:34
-
-
Save Hexlord/eb19453dd4fd0abe14638a88ffc36212 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <flecs.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#define MILLION (1000 * 1000) | |
#define ENTITY_COUNT (100) | |
#define SAMPLE_COUNT (1000) | |
struct Comp1 { | |
int field1; | |
int field2; | |
}; | |
struct Comp2 { | |
int field1; | |
int field2; | |
}; | |
struct Comp3 { | |
int field1; | |
int field2; | |
}; | |
bool flip_coin() { | |
int r = rand(); | |
return r >= ((float)RAND_MAX / 2.0f); | |
} | |
int main(int argc, char *argv[]) { | |
flecs::world World; | |
World.use<Comp1>(); | |
World.use<Comp2>(); | |
World.use<Comp3>(); | |
ecs_world_t *world = World.c_ptr(); | |
ecs_log_set_level(0); | |
ecs_time_t t = {0}; | |
// Create component ids | |
ecs_time_measure(&t); | |
// Record table count before creating entities | |
const ecs_world_info_t *info = ecs_get_world_info(world); | |
int32_t table_count = info->table_count; | |
// Report # of created tables | |
printf("\n"); | |
ecs_trace("querying for 3 components"); | |
ecs_trace("taking %d samples", SAMPLE_COUNT); | |
ecs_trace("each time creating %d entities in unique tables", ENTITY_COUNT); | |
ecs_trace(""); | |
ecs_entity_t Ids[] = {World.entity(), World.entity(), World.entity(), | |
World.entity(), World.entity(), World.entity(), | |
World.entity(), World.entity(), World.entity(), | |
World.entity(), World.entity(), World.entity(), | |
World.entity(), World.entity(), World.entity()}; | |
/* Creation */ | |
{ | |
double sum = 0, min = 10e10, max = 0; | |
for (int s = 0; s < SAMPLE_COUNT; s++) { | |
// Create entities | |
ecs_entity_t Entities[ENTITY_COUNT]; | |
flecs::entity Parent; | |
ecs_time_measure(&t); | |
Parent = World.entity(); | |
for (int i = 0; i < ENTITY_COUNT; i++) { | |
auto E = World.entity(); | |
for (auto Id : Ids) { | |
E.add(Id); | |
} | |
E.add(ecs_pair(flecs::ChildOf, Parent)); | |
Entities[i] = E; | |
} | |
for (auto E : Entities) { | |
World.entity(E).destruct(); | |
} | |
Parent.destruct(); | |
double v = ecs_time_measure(&t); | |
min = v < min ? v : min; | |
max = v > max ? v : max; | |
sum += v; | |
} | |
sum /= (double)SAMPLE_COUNT; | |
ecs_trace("creation: min: %.2fus, avg: %.2fus, max: %.2fus", | |
min * MILLION, sum * MILLION, max * MILLION); | |
} | |
/* Creation 2 */ | |
{ | |
double sum = 0, min = 10e10, max = 0; | |
for (int s = 0; s < SAMPLE_COUNT; s++) { | |
// Create entities | |
ecs_entity_t Entities[ENTITY_COUNT]; | |
flecs::entity Parent; | |
ecs_time_measure(&t); | |
Parent = World.entity(); | |
for (int i = 0; i < ENTITY_COUNT; i++) { | |
auto E = World.entity(); | |
World.scope(Parent, [&]() { | |
auto E = World.entity(); | |
for (auto Id : Ids) { | |
E.add(Id); | |
} | |
Entities[i] = E; | |
}); | |
} | |
for (auto E : Entities) { | |
World.entity(E).destruct(); | |
} | |
Parent.destruct(); | |
double v = ecs_time_measure(&t); | |
min = v < min ? v : min; | |
max = v > max ? v : max; | |
sum += v; | |
} | |
sum /= (double)SAMPLE_COUNT; | |
ecs_trace("creation: min: %.2fus, avg: %.2fus, max: %.2fus", | |
min * MILLION, sum * MILLION, max * MILLION); | |
} | |
/* Progress */ | |
{ | |
double sum = 0, min = 10e10, max = 0; | |
for (int s = 0; s < SAMPLE_COUNT; s++) { | |
ecs_time_measure(&t); | |
World.progress(); | |
double v = ecs_time_measure(&t); | |
min = v < min ? v : min; | |
max = v > max ? v : max; | |
sum += v; | |
} | |
sum /= (double)SAMPLE_COUNT; | |
ecs_trace("progress: min: %.2fus, avg: %.2fus, max: %.2fus", | |
min * MILLION, sum * MILLION, max * MILLION); | |
} | |
ecs_trace(""); | |
printf("\n"); | |
ecs_log_set_level(-1); | |
return 0; | |
} | |
/home/sasha/flecs_test/cmake-build-release/SECore | |
info: querying for 3 components | |
info: taking 1000 samples | |
info: each time creating 100 entities in unique tables | |
info: | |
info: creation: min: 229.27us, avg: 275.16us, max: 623.97us | |
info: creation: min: 404.74us, avg: 455.63us, max: 978.57us | |
info: progress: min: 0.51us, avg: 0.57us, max: 22.17us | |
info: | |
Process finished with exit code 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment