Improving Performance Benchmark (#1695)

Taking measurements for frames and LateUpdate at same time.
This commit is contained in:
James Frowen 2020-04-12 00:52:48 +01:00 committed by GitHub
parent 79b04661f5
commit 18bd792a0b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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();
}
}
}