|
| 1 | +# Measure.Frames() |
| 2 | + |
| 3 | +Records time per frame by default and provides additional properties/methods to control how the measurements are taken: |
| 4 | +* **WarmupCount(int n)** - number of times to execute before measurements are collected. If unspecified, a default warmup is executed for 80 ms or until at least 3 full frames have rendered, whichever is longest. |
| 5 | +* **MeasurementCount(int n)** - number of frames to capture measurements for. If this value is not specified, as many frames as possible are captured until approximately 500 ms has elapsed. |
| 6 | +* **DontRecordFrametime()** - disables frametime measurement. |
| 7 | +* **ProfilerMarkers(...)** - sample profile markers per frame. Does not work for deep profiling and `Profiler.BeginSample()` |
| 8 | +* **SampleGroup(string name)** - name of the measurement, defaults to "Time" if unspecified. |
| 9 | +* **Scope()** - measures frame times in a given coroutine scope. |
| 10 | + |
| 11 | + |
| 12 | +#### Example 1: Simple frame time measurement using default values of at least 7 frames and default WarmupCount (see description above). |
| 13 | + |
| 14 | +``` csharp |
| 15 | +[UnityTest, Performance] |
| 16 | +public IEnumerator Test() |
| 17 | +{ |
| 18 | + ... |
| 19 | + |
| 20 | + yield return Measure.Frames().Run(); |
| 21 | +} |
| 22 | +``` |
| 23 | + |
| 24 | +#### Example 2: Sample profile markers per frame, disable frametime measurement |
| 25 | + |
| 26 | +If you'd like to sample profiler markers across multiple frames and don't need to record frametime, it is possible to disable the frame time measurement. |
| 27 | + |
| 28 | +``` csharp |
| 29 | +[UnityTest, Performance] |
| 30 | +public IEnumerator Test() |
| 31 | +{ |
| 32 | + ... |
| 33 | + |
| 34 | + yield return Measure.Frames() |
| 35 | + .ProfilerMarkers(...) |
| 36 | + .DontRecordFrametime() |
| 37 | + .Run(); |
| 38 | +} |
| 39 | +``` |
| 40 | + |
| 41 | +#### Example 3: Sample frame times in a scope |
| 42 | + |
| 43 | +``` csharp |
| 44 | +[UnityTest, Performance] |
| 45 | +public IEnumerator Test() |
| 46 | +{ |
| 47 | + using (Measure.Frames().Scope()) |
| 48 | + { |
| 49 | + yield return ...; |
| 50 | + } |
| 51 | +} |
| 52 | +``` |
| 53 | + |
| 54 | +#### Example 4: Specify custom WarmupCount and MeasurementCount per frame |
| 55 | + |
| 56 | +If you want more control, you can specify how many frames you want to measure. |
| 57 | + |
| 58 | +``` csharp |
| 59 | +[UnityTest, Performance] |
| 60 | +public IEnumerator Test() |
| 61 | +{ |
| 62 | + ... |
| 63 | + |
| 64 | + yield return Measure.Frames() |
| 65 | + .WarmupCount(5) |
| 66 | + .MeasurementCount(10) |
| 67 | + .Run(); |
| 68 | +} |
| 69 | +``` |
0 commit comments