mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
Improving Performance Benchmark (#1695)
Taking measurements for frames and LateUpdate at same time.
This commit is contained in:
parent
79b04661f5
commit
18bd792a0b
@ -21,6 +21,7 @@ public class BenchmarkPerformance
|
|||||||
|
|
||||||
readonly SampleGroupDefinition NetworkManagerSample = new SampleGroupDefinition("NetworkManagerLateUpdate", SampleUnit.Millisecond, AggregationType.Average);
|
readonly SampleGroupDefinition NetworkManagerSample = new SampleGroupDefinition("NetworkManagerLateUpdate", SampleUnit.Millisecond, AggregationType.Average);
|
||||||
readonly Stopwatch stopwatch = new Stopwatch();
|
readonly Stopwatch stopwatch = new Stopwatch();
|
||||||
|
|
||||||
bool captureMeasurement;
|
bool captureMeasurement;
|
||||||
void BeforeLateUpdate()
|
void BeforeLateUpdate()
|
||||||
{
|
{
|
||||||
@ -68,18 +69,32 @@ public IEnumerator SetUp()
|
|||||||
benchmarker.AfterLateUpdate = AfterLateUpdate;
|
benchmarker.AfterLateUpdate = AfterLateUpdate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IEnumerator RunBenchmark()
|
||||||
|
{
|
||||||
|
// warmup
|
||||||
|
yield return new WaitForSecondsRealtime(Warmup);
|
||||||
|
|
||||||
|
// run benchmark
|
||||||
|
// capture frames and LateUpdate time
|
||||||
|
|
||||||
|
captureMeasurement = true;
|
||||||
|
|
||||||
|
yield return Measure.Frames().MeasurementCount(MeasureCount).Run();
|
||||||
|
|
||||||
|
captureMeasurement = false;
|
||||||
|
}
|
||||||
|
|
||||||
[UnityTearDown]
|
[UnityTearDown]
|
||||||
public IEnumerator TearDown()
|
public IEnumerator TearDown()
|
||||||
{
|
{
|
||||||
// run benchmark
|
|
||||||
yield return Measure.Frames().MeasurementCount(MeasureCount).Run();
|
|
||||||
|
|
||||||
// shutdown
|
// shutdown
|
||||||
GameObject go = NetworkManager.singleton.gameObject;
|
GameObject go = NetworkManager.singleton.gameObject;
|
||||||
NetworkManager.Shutdown();
|
NetworkManager.Shutdown();
|
||||||
// unload scene
|
// unload scene
|
||||||
Scene scene = SceneManager.GetSceneByPath(ScenePath);
|
Scene scene = SceneManager.GetSceneByPath(ScenePath);
|
||||||
yield return SceneManager.UnloadSceneAsync(scene);
|
yield return SceneManager.UnloadSceneAsync(scene);
|
||||||
|
|
||||||
|
// we must destroy networkmanager because it is marked as DontDestroyOnLoad
|
||||||
if (go != null)
|
if (go != null)
|
||||||
{
|
{
|
||||||
UnityEngine.Object.Destroy(go);
|
UnityEngine.Object.Destroy(go);
|
||||||
@ -104,17 +119,8 @@ static void EnableHealth(bool value)
|
|||||||
public IEnumerator Benchmark10k()
|
public IEnumerator Benchmark10k()
|
||||||
{
|
{
|
||||||
EnableHealth(true);
|
EnableHealth(true);
|
||||||
// warmup
|
|
||||||
yield return new WaitForSecondsRealtime(Warmup);
|
|
||||||
|
|
||||||
captureMeasurement = true;
|
yield return RunBenchmark();
|
||||||
|
|
||||||
for (int i = 0; i < MeasureCount; i++)
|
|
||||||
{
|
|
||||||
yield return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
captureMeasurement = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[UnityTest]
|
[UnityTest]
|
||||||
@ -127,17 +133,7 @@ public IEnumerator Benchmark10kIdle()
|
|||||||
{
|
{
|
||||||
EnableHealth(false);
|
EnableHealth(false);
|
||||||
|
|
||||||
// warmup
|
yield return RunBenchmark();
|
||||||
yield return new WaitForSecondsRealtime(Warmup);
|
|
||||||
|
|
||||||
captureMeasurement = true;
|
|
||||||
|
|
||||||
for (int i = 0; i < MeasureCount; i++)
|
|
||||||
{
|
|
||||||
yield return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
captureMeasurement = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user