Material Clustering Benchmark
BenchmarkHelper.cs
Go to the documentation of this file.
1using System;
2
3public static class BenchmarkHelper
4{
5 private static readonly System.Diagnostics.Stopwatch stopwatch =
6 new System.Diagnostics.Stopwatch();
7
8 private static void RunWithoutGC(Action action)
9 {
10 var savedGCMode = UnityEngine.Scripting.GarbageCollector.GCMode;
11
12 UnityEngine.Scripting.GarbageCollector.GCMode = UnityEngine
13 .Scripting
14 .GarbageCollector
15 .Mode
16 .Disabled;
17 {
18 // no GC section
19 action();
20 }
21 UnityEngine.Scripting.GarbageCollector.GCMode = savedGCMode;
22 }
23
24 /// <summary>
25 /// Runs the provided <paramref name="action" /> and measures the time it required to finish. Ensures GC will not trigger while running the action, as it would interfere with the measurement.
26 /// </summary>
27 /// <param name="action">Action to run.</param>
28 /// <returns>Time in milliseconds.</returns>
29 public static long MeasureTime(Action action)
30 {
31 stopwatch.Restart();
32 RunWithoutGC(action);
33 stopwatch.Stop();
34 return stopwatch.ElapsedMilliseconds;
35 }
36}
static long MeasureTime(Action action)
Runs the provided action and measures the time it required to finish. Ensures GC will not trigger wh...