Last active
April 1, 2022 19:14
-
-
Save Hexlord/5f79a834ce905ca77ff71faea8599a96 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 <ctime> | |
#include <cstdio> | |
#include "flecs.h" | |
#include "inttypes.h" | |
auto nanos() { | |
timespec Time; | |
clock_gettime(CLOCK_MONOTONIC, &Time); | |
return Time.tv_sec * int64_t{1000000000} + (int64_t)Time.tv_nsec; | |
} | |
int main() { | |
struct Comp1 { | |
int field1; | |
int field2; | |
}; | |
struct Comp2 { | |
int field1; | |
int field2; | |
}; | |
struct Comp3 { | |
int field1; | |
int field2; | |
}; | |
float Baseline; | |
{ | |
// Warm-up | |
flecs::world ECS; | |
ECS.progress(); | |
auto Start = nanos(); | |
ECS.progress(); | |
auto End = nanos(); | |
Baseline = (End - Start) / 1000000000.0f; | |
} | |
{ | |
flecs::world ECS; | |
int Count = 0; | |
ECS.system<Comp1, Comp2, Comp3>().iter([&](flecs::iter &Iter) { | |
for (auto Index : Iter) { | |
auto Entity = Iter.entity(Index); | |
(void)Entity; | |
++Count; | |
} | |
}); | |
for (int Index = 0; Index < 12800; ++Index) { | |
ECS.entity().add<Comp1>().add<Comp2>().add<Comp3>(); | |
} | |
ECS.progress(); | |
auto Start = nanos(); | |
ECS.progress(); | |
auto End = nanos(); | |
printf("test 1 took %.3fms\n", ((End - Start) / 1000000000.0f - Baseline) * 1000.0f); | |
} | |
{ | |
flecs::world ECS; | |
int Count = 0; | |
ECS.system<Comp1, Comp2, Comp3>().iter([&](flecs::iter &Iter) { | |
for (auto Index : Iter) { | |
auto Entity = Iter.entity(Index); | |
(void)Entity; | |
++Count; | |
} | |
}); | |
for (int Index = 0; Index < 12800; ++Index) { | |
auto Parent = ECS.entity(); | |
ECS.scope(Parent, [&]() { ECS.entity().add<Comp1>().add<Comp2>().add<Comp3>(); }); | |
} | |
ECS.progress(); | |
auto Start = nanos(); | |
ECS.progress(); | |
auto End = nanos(); | |
printf("test 2 took %.3fms\n", ((End - Start) / 1000000000.0f - Baseline) * 1000.0f); | |
} | |
return 0; | |
} | |
Output @HEAD aka aa3d0df9: | |
/home/sasha/flecs_test/cmake-build-release/SECore | |
test 1 took 0.036ms | |
test 2 took 4.527ms | |
Output @HEAD~100: | |
/home/sasha/flecs_test/cmake-build-release/SECore | |
test 1 took 0.038ms | |
test 2 took 4.207ms | |
Output @HEAD~200: | |
/home/sasha/flecs_test/cmake-build-release/SECore | |
test 1 took 0.033ms | |
test 2 took 5.887ms | |
Output @HEAD~225: | |
/home/sasha/flecs_test/cmake-build-release/SECore | |
test 1 took 0.040ms | |
test 2 took 5.132ms | |
Output @HEAD~230: | |
/home/sasha/flecs_test/cmake-build-release/SECore | |
test 1 took 0.034ms | |
test 2 took 5.427ms | |
Output @HEAD~232: | |
/home/sasha/flecs_test/cmake-build-release/SECore | |
test 1 took 0.037ms | |
test 2 took 5.620ms | |
Output @HEAD~233: | |
/home/sasha/flecs_test/cmake-build-release/SECore | |
test 1 took 0.010ms | |
test 2 took 0.356ms | |
Output @HEAD~235: | |
/home/sasha/flecs_test/cmake-build-release/SECore | |
test 1 took 0.010ms | |
test 2 took 0.345ms | |
Output @HEAD~250: | |
/home/sasha/flecs_test/cmake-build-release/SECore | |
test 1 took 0.011ms | |
test 2 took 0.388ms | |
Output @HEAD~300: | |
/home/sasha/flecs_test/cmake-build-release/SECore | |
test 1 took 0.023ms | |
test 2 took 0.375ms | |
Output @HEAD~800: | |
/home/sasha/flecs_test/cmake-build-release/SECore | |
test 1 took 0.013ms | |
test 2 took 0.656ms | |
Output @HEAD~1000: | |
/home/sasha/flecs_test/cmake-build-release/SECore | |
test 1 took 0.016ms | |
test 2 took 0.130ms | |
Output @HEAD~1100: | |
/home/sasha/flecs_test/cmake-build-release/SECore | |
test 1 took 0.013ms | |
test 2 took 0.201ms |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment