Skip to content

Commit 88aa96d

Browse files
BrianWill-UnityDOTS Publisher
authored andcommitted
Publishing samples for Entities 0.14
Co-authored-by: DOTS Publisher <noreply@unity3d.com>
1 parent ec16fed commit 88aa96d

12 files changed

+5194
-63
lines changed

ECSSamples/Assets/Advanced/SubsceneWithBuildConfigurations/SetBuildConfigurationComponent.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,6 @@ private void OnEnable()
6969
}
7070

7171
OnValidate();
72-
73-
var playerLoop = PlayerLoop.GetDefaultPlayerLoop(); // TODO(DOTS-2283): shouldn't stomp the default player loop here
74-
ScriptBehaviourUpdateOrder.AddWorldToPlayerLoop(worldA, ref playerLoop);
75-
ScriptBehaviourUpdateOrder.AddWorldToPlayerLoop(worldB, ref playerLoop);
76-
PlayerLoop.SetPlayerLoop(playerLoop);
7772
}
7873

7974
private void OnDisable()
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using UnityEngine;
2+
3+
public class FloatStatistic
4+
{
5+
public float Mean { get; private set; }
6+
public float Sigma { get; private set; }
7+
public int Count { get; private set; }
8+
9+
public void AddValue(float value)
10+
{
11+
sum += value;
12+
sumSquared += value * value;
13+
Count++;
14+
15+
Mean = (float)(sum / Count);
16+
var sigmaSq = (float)(sumSquared / Count - (Mean * Mean));
17+
var sigma = sigmaSq;
18+
if (sigmaSq > Mathf.Epsilon)
19+
{
20+
sigma = Mathf.Sqrt(sigmaSq);
21+
}
22+
Sigma = sigma;
23+
}
24+
25+
double sum;
26+
double sumSquared;
27+
}

ECSSamples/Assets/StressTests/FloatStatistic.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ECSSamples/Assets/StressTests/ManySystems_Complex/ManySystems_Complex_Bootstrap.cs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Diagnostics;
34
using Unity.Collections;
45
using Unity.Collections.LowLevel.Unsafe;
56
using Unity.Entities;
@@ -15,21 +16,31 @@ namespace StressTests.ManySystems
1516
/// </summary>
1617
public class ManySystems_Complex_Bootstrap : MonoBehaviour
1718
{
19+
[Range(1, 1000)]
1820
public int NumSystems = 1000;
1921
public int NumEntities = 1000;
2022
public bool UseSchedule = true;
2123
public float ReadOnlyProbability = .5f;
2224
public float ComponentIncludeProbability = .5f;
25+
public int SettleCount = 1000;
26+
public int TargetCount = 10000;
2327

2428
TestSystem_Complex[] m_Systems;
29+
readonly FloatStatistic m_Stats = new FloatStatistic();
30+
readonly Stopwatch m_StopWatch = new Stopwatch();
31+
int m_Count;
2532

2633
// Start is called before the first frame update
2734
void Start()
2835
{
36+
m_Count = -SettleCount;
2937
m_Systems = new TestSystem_Complex[NumSystems];
38+
string systemName = "TestSystem_Complex";
3039
for (int i = 0; i < NumSystems; i++)
3140
{
32-
m_Systems[i] = new TestSystem_Complex();
41+
var typeName = $"StressTests.ManySystems.{systemName}_{i:0000}";
42+
var type = Type.GetType(typeName);
43+
m_Systems[i] = (TestSystem_Complex)Activator.CreateInstance(type);
3344
m_Systems[i].UseRun = !UseSchedule;
3445
m_Systems[i].Types = RandomTypes();
3546
}
@@ -73,8 +84,26 @@ ComponentType[] RandomTypes()
7384

7485
void Update()
7586
{
87+
++m_Count;
88+
m_StopWatch.Reset();
89+
m_StopWatch.Start();
7690
foreach (var s in m_Systems)
7791
s.Update();
92+
m_StopWatch.Stop();
93+
94+
if ((m_Count >= 0) && (m_Count <= TargetCount))
95+
{
96+
m_Stats.AddValue(m_StopWatch.ElapsedMilliseconds);
97+
98+
if ((m_Stats.Count % 1000) == 0)
99+
{
100+
UnityEngine.Debug.Log($"{m_Stats.Count} samples Mean {m_Stats.Mean}ms +/- {m_Stats.Sigma}ms");
101+
}
102+
}
103+
if (m_Stats.Count == TargetCount)
104+
{
105+
UnityEngine.Debug.Log($"{m_Stats.Count} samples Mean {m_Stats.Mean}ms +/- {m_Stats.Sigma}ms");
106+
}
78107
}
79108
}
80109

ECSSamples/Assets/StressTests/ManySystems_Complex/ManySystems_Complex_Bootstrap_Systems.cs

Lines changed: 1004 additions & 0 deletions
Large diffs are not rendered by default.

ECSSamples/Assets/StressTests/ManySystems_Complex/ManySystems_Complex_Bootstrap_Systems.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ECSSamples/Assets/StressTests/ManySystems_Linear/ManySystems_Linear_Bootstrap.cs

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using System;
2+
using System.Diagnostics;
13
using Unity.Collections;
24
using Unity.Entities;
35
using UnityEngine;
@@ -9,33 +11,44 @@ namespace StressTests.ManySystems
911
/// </summary>
1012
public class ManySystems_Linear_Bootstrap : MonoBehaviour
1113
{
14+
[Range(1, 1000)]
1215
public int NumSystems = 1000;
1316
public int NumEntities = 1000;
1417
public bool UseSchedule = true;
1518
public bool ReadOnly = false;
19+
public int SettleCount = 1000;
20+
public int TargetCount = 10000;
1621

1722
SystemBase[] m_Systems;
23+
readonly FloatStatistic m_Stats = new FloatStatistic();
24+
readonly Stopwatch m_StopWatch = new Stopwatch();
25+
int m_Count;
1826

1927
// Start is called before the first frame update
2028
void Start()
2129
{
30+
m_Count = -SettleCount;
2231
m_Systems = new SystemBase[NumSystems];
23-
for (int i = 0; i < NumSystems; i++)
32+
string systemName;
33+
if (UseSchedule)
2434
{
25-
if (UseSchedule)
26-
{
27-
if (ReadOnly)
28-
m_Systems[i] = new TestSystem_ScheduleReader();
29-
else
30-
m_Systems[i] = new TestSystem_Schedule();
31-
}
35+
if (ReadOnly)
36+
systemName = "TestSystem_ScheduleReader";
3237
else
33-
{
34-
if (ReadOnly)
35-
m_Systems[i] = new TestSystem_RunReader();
36-
else
37-
m_Systems[i] = new TestSystem_Run();
38-
}
38+
systemName = "TestSystem_Schedule";
39+
}
40+
else
41+
{
42+
if (ReadOnly)
43+
systemName = "TestSystem_RunReader";
44+
else
45+
systemName = "TestSystem_Run";
46+
}
47+
for (int i = 0; i < NumSystems; i++)
48+
{
49+
var typeName = $"StressTests.ManySystems.{systemName}_{i:0000}";
50+
var type = Type.GetType(typeName);
51+
m_Systems[i] = (SystemBase)Activator.CreateInstance(type);
3952
}
4053

4154
var world = World.DefaultGameObjectInjectionWorld;
@@ -48,8 +61,26 @@ void Start()
4861

4962
void Update()
5063
{
64+
++m_Count;
65+
m_StopWatch.Reset();
66+
m_StopWatch.Start();
5167
foreach (var s in m_Systems)
5268
s.Update();
69+
m_StopWatch.Stop();
70+
71+
if ((m_Count >= 0) && (m_Count <= TargetCount))
72+
{
73+
m_Stats.AddValue(m_StopWatch.ElapsedMilliseconds);
74+
75+
if ((m_Stats.Count % 1000) == 0)
76+
{
77+
UnityEngine.Debug.Log($"{m_Stats.Count} samples Mean {m_Stats.Mean}ms +/- {m_Stats.Sigma}ms");
78+
}
79+
}
80+
if (m_Stats.Count == TargetCount)
81+
{
82+
UnityEngine.Debug.Log($"{m_Stats.Count} samples Mean {m_Stats.Mean}ms +/- {m_Stats.Sigma}ms");
83+
}
5384
}
5485
}
5586

0 commit comments

Comments
 (0)