Created
January 28, 2022 19:46
-
-
Save Hexlord/6cd8bca616f34355c40faf3b249ded56 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
void TestPrefabPerformance(ecs &ECS) { | |
constexpr uint32 Count = 100000; | |
TStackArray<entity_view, Count> Entities; | |
struct CComp1 { | |
uint64 Field1; | |
uint64 Field2; | |
uint64 Field3; | |
uint64 Field4; | |
uint64 Field5; | |
char Field6; | |
}; | |
struct CComp2 { | |
entity_view Field1; | |
}; | |
struct CComp3 { | |
char Field1; | |
}; | |
auto Start1 = Time::GetClock(); | |
auto Prefab = ECS.prefab().set<CComp1>({{}, {}, 3, {}, {}, {}}).set<CComp2>({}).set<CComp3>({7}); | |
for(uint32 Index = 0; Index < Count; ++Index) { | |
auto Tower = ECS.entity().is_a(Prefab); | |
Entities.Add(Tower); | |
} | |
auto End1 = Time::GetClock(); | |
auto Start2 = Time::GetClock(); | |
for(auto Entity : Entities) { | |
auto Comp1 = Entity.get<CComp1>(); | |
Check(Comp1->Field3 == 3); | |
VolatileValue = Comp1->Field3; | |
auto Comp3 = Entity.get<CComp3>(); | |
Check(Comp3->Field1 == 7); | |
VolatileValue = Comp3->Field1; | |
} | |
auto End2 = Time::GetClock(); | |
auto Start3 = Time::GetClock(); | |
ECS.filter_builder<CComp1, CComp3>().build().iter([&](iter &Iter, CComp1 *Comp1s, CComp3 *Comp3s) { | |
for(auto Index : Iter) { | |
Check(Comp1s[Index].Field3 == 3); | |
VolatileValue = Comp1s[Index].Field3; | |
Check(Comp3s[Index].Field1 == 7); | |
VolatileValue = Comp3s[Index].Field1; | |
} | |
}); | |
auto End3 = Time::GetClock(); | |
auto Query = ECS.query_builder<CComp1, CComp3>().build(); | |
auto Start4 = Time::GetClock(); | |
Query.iter([&](iter &Iter, CComp1 *Comp1s, CComp3 *Comp3s) { | |
for(auto Index : Iter) { | |
Check(Comp1s[Index].Field3 == 3); | |
VolatileValue = Comp1s[Index].Field3; | |
Check(Comp3s[Index].Field1 == 7); | |
VolatileValue = Comp3s[Index].Field1; | |
} | |
}); | |
auto End4 = Time::GetClock(); | |
Outputf("Shared creation finished in %.6f seconds\n", Time::ClockToTime(End1 - Start1)); | |
Outputf("Shared .get access finished in %.6f seconds\n", Time::ClockToTime(End2 - Start2)); | |
Outputf("Shared filter finished in %.6f seconds\n", Time::ClockToTime(End3 - Start3)); | |
Outputf("Shared query finished in %.6f seconds\n", Time::ClockToTime(End4 - Start4)); | |
} | |
void TestOwnedPrefabPerformance(ecs &ECS) { | |
constexpr uint32 Count = 100000; | |
TStackArray<entity_view, Count> Entities; | |
struct CComp1 { | |
uint64 Field1; | |
uint64 Field2; | |
uint64 Field3; | |
uint64 Field4; | |
uint64 Field5; | |
char Field6; | |
}; | |
struct CComp2 { | |
entity_view Field1; | |
}; | |
struct CComp3 { | |
char Field1; | |
}; | |
auto Start1 = Time::GetClock(); | |
auto Prefab = ECS.prefab().set<CComp1>({{}, {}, 3, {}, {}, {}}).override<CComp1>().set<CComp2>({}).override<CComp2>().set<CComp3>({7}).override<CComp3>(); | |
for(uint32 Index = 0; Index < Count; ++Index) { | |
auto Tower = ECS.entity().is_a(Prefab); | |
Entities.Add(Tower); | |
} | |
auto End1 = Time::GetClock(); | |
auto Start2 = Time::GetClock(); | |
for(auto Entity : Entities) { | |
auto Comp1 = Entity.get<CComp1>(); | |
Check(Comp1->Field3 == 3); | |
VolatileValue = Comp1->Field3; | |
auto Comp3 = Entity.get<CComp3>(); | |
Check(Comp3->Field1 == 7); | |
VolatileValue = Comp3->Field1; | |
} | |
auto End2 = Time::GetClock(); | |
auto Start3 = Time::GetClock(); | |
ECS.filter_builder<CComp1, CComp3>().build().iter([&](iter &Iter, CComp1 *Comp1s, CComp3 *Comp3s) { | |
for(auto Index : Iter) { | |
Check(Comp1s[Index].Field3 == 3); | |
VolatileValue = Comp1s[Index].Field3; | |
Check(Comp3s[Index].Field1 == 7); | |
VolatileValue = Comp3s[Index].Field1; | |
} | |
}); | |
auto End3 = Time::GetClock(); | |
auto Query = ECS.query_builder<CComp1, CComp3>().build(); | |
auto Start4 = Time::GetClock(); | |
Query.iter([&](iter &Iter, CComp1 *Comp1s, CComp3 *Comp3s) { | |
for(auto Index : Iter) { | |
Check(Comp1s[Index].Field3 == 3); | |
VolatileValue = Comp1s[Index].Field3; | |
Check(Comp3s[Index].Field1 == 7); | |
VolatileValue = Comp3s[Index].Field1; | |
} | |
}); | |
auto End4 = Time::GetClock(); | |
Outputf("Owned creation finished in %.6f seconds\n", Time::ClockToTime(End1 - Start1)); | |
Outputf("Owned .get access finished in %.6f seconds\n", Time::ClockToTime(End2 - Start2)); | |
Outputf("Owned filter finished in %.6f seconds\n", Time::ClockToTime(End3 - Start3)); | |
Outputf("Owned query finished in %.6f seconds\n", Time::ClockToTime(End4 - Start4)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment