diff --git a/Assets/Mirror/Tests/Performance/Runtime/BenchmarkPerformance.cs b/Assets/Mirror/Tests/Performance/Runtime/BenchmarkPerformance.cs index 178444ccc..03e2b7859 100644 --- a/Assets/Mirror/Tests/Performance/Runtime/BenchmarkPerformance.cs +++ b/Assets/Mirror/Tests/Performance/Runtime/BenchmarkPerformance.cs @@ -21,6 +21,7 @@ public class BenchmarkPerformance readonly SampleGroupDefinition NetworkManagerSample = new SampleGroupDefinition("NetworkManagerLateUpdate", SampleUnit.Millisecond, AggregationType.Average); readonly Stopwatch stopwatch = new Stopwatch(); + bool captureMeasurement; void BeforeLateUpdate() { @@ -68,18 +69,32 @@ public IEnumerator SetUp() 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] public IEnumerator TearDown() { - // run benchmark - yield return Measure.Frames().MeasurementCount(MeasureCount).Run(); - // shutdown GameObject go = NetworkManager.singleton.gameObject; NetworkManager.Shutdown(); // unload scene Scene scene = SceneManager.GetSceneByPath(ScenePath); yield return SceneManager.UnloadSceneAsync(scene); + + // we must destroy networkmanager because it is marked as DontDestroyOnLoad if (go != null) { UnityEngine.Object.Destroy(go); @@ -104,17 +119,8 @@ static void EnableHealth(bool value) public IEnumerator Benchmark10k() { EnableHealth(true); - // warmup - yield return new WaitForSecondsRealtime(Warmup); - captureMeasurement = true; - - for (int i = 0; i < MeasureCount; i++) - { - yield return null; - } - - captureMeasurement = false; + yield return RunBenchmark(); } [UnityTest] @@ -127,17 +133,7 @@ public IEnumerator Benchmark10kIdle() { EnableHealth(false); - // warmup - yield return new WaitForSecondsRealtime(Warmup); - - captureMeasurement = true; - - for (int i = 0; i < MeasureCount; i++) - { - yield return null; - } - - captureMeasurement = false; + yield return RunBenchmark(); } } }