Skip to content

Commit ccb4db0

Browse files
author
Unity Technologies
committed
com.unity.test-framework.performance@2.7.0-preview
## [2.7.0] - 2021-02-19 Reduce metadata overhead when running locally by caching dependencies Remove the need for link.xml Restructured documentation Fixed method measurement IterationsPerMeasurement ## [2.6.0] - 2021-01-12 Add build configuration support
1 parent db44d8a commit ccb4db0

31 files changed

+738
-547
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
## [2.7.0] - 2021-02-19
4+
5+
Reduce metadata overhead when running locally by caching dependencies
6+
Remove the need for link.xml
7+
Restructured documentation
8+
Fixed method measurement IterationsPerMeasurement
9+
310
## [2.6.0] - 2021-01-12
411

512
Add build configuration support

Documentation~/TableOfContents.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
* [Performance Testing Extension overview](./index.md)
2+
* [Taking measurements](./taking-measurements.md)
3+
* [Measure.Method](./measure-method.md)
4+
* [Measure.Frames](./measure-frames.md)
5+
* [Measure.Scope](./measure-scope.md)
6+
* [Measure.ProfileMarkers](./measure-profile-markers.md)
7+
* [Measure.Custom](./measure-custom.md)
8+
* [Writing tests](./writing-tests.md)
9+
* [Viewing results](./viewing-results.md)
10+
* [Reference](./reference.md)

Documentation~/index.md

Lines changed: 18 additions & 487 deletions
Large diffs are not rendered by default.

Documentation~/measure-custom.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Measure.Custom()
2+
3+
When you want to record samples outside of frame time, method time, or profiler markers, use a custom measurement. It can be any value.
4+
5+
#### Example: Use a custom measurement to capture total allocated memory
6+
7+
``` csharp
8+
[Test, Performance]
9+
public void Test()
10+
{
11+
SampleGroup samplegroup = new SampleGroup("TotalAllocatedMemory", SampleUnit.Megabyte, false);
12+
var allocatedMemory = Profiler.GetTotalAllocatedMemoryLong() / 1048576f
13+
Measure.Custom(samplegroup, allocatedMemory);
14+
15+
}
16+
```

Documentation~/measure-frames.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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+
```

Documentation~/measure-method.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Measure.Method()
2+
3+
Executes the provided method, sampling performance using the following 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 100 ms or until at least 3 method executions have completed, whichever is longer.
5+
* **MeasurementCount(int n)** - number of measurements to capture, defaults to 9 if not specified.
6+
* **IterationsPerMeasurement(int n)** - number of method executions per measurement to use. If this value is not specified, the method is executed as many times as possible until approximately 100 ms has elapsed.
7+
* **SampleGroup(string name)** - name of the measurement, defaults to "Time" if unspecified.
8+
* **GC()** - if specified, measures the total number of Garbage Collection allocation calls.
9+
* **SetUp(Action action)** - is called every iteration before method execution. Setup time is not measured.
10+
* **CleanUp(Action action)** - is called every iteration after method execution. Cleanup time is not measured.
11+
12+
13+
#### Example 1: Simple method measurement using default values
14+
15+
``` csharp
16+
[Test, Performance]
17+
public void Test()
18+
{
19+
Measure.Method(() => { ... }).Run();
20+
}
21+
```
22+
23+
#### Example 2: Customize Measure.Method properties
24+
25+
```
26+
[Test, Performance]
27+
public void Test()
28+
{
29+
Measure.Method(() => { ... })
30+
.WarmupCount(10)
31+
.MeasurementCount(10)
32+
.IterationsPerMeasurement(5)
33+
.GC()
34+
.SetUp(()=> {/*setup code*/})
35+
.CleanUp(()=> {/*cleanup code*/})
36+
.Run();
37+
}
38+
```
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Measure.ProfilerMarkers()
2+
3+
Used to record profiler markers. Profiler marker timings are recorded automatically and sampled within the scope of the `using` statement. Names should match profiler marker labels. Profiler markers are sampled once per frame. Sampling the same profiler marker per frame will result in the sum of all invocations. Note that deep and editor profiling is not available. Profiler markers created using `Profiler.BeginSample()` are not supported, switch to `ProfilerMarker` if possible.
4+
5+
#### Example: Measuring profiler markers in a scope
6+
7+
``` csharp
8+
[Test, Performance]
9+
public void Test()
10+
{
11+
string[] markers =
12+
{
13+
"Instantiate",
14+
"Instantiate.Copy",
15+
"Instantiate.Produce",
16+
"Instantiate.Awake"
17+
};
18+
19+
using(Measure.ProfilerMarkers(markers))
20+
{
21+
...
22+
}
23+
}
24+
```

Documentation~/measure-scope.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Measure.Scope(string name = "Time")
2+
3+
Measures execution time for the scope as a single time, for both synchronous and coroutine methods. Passing the name argument overrides the name of the created SampleGroup.
4+
5+
#### Example: Measuring a scope; execution time is measured for everything in the using statement
6+
7+
``` csharp
8+
[Test, Performance]
9+
public void Test()
10+
{
11+
using(Measure.Scope())
12+
{
13+
...
14+
}
15+
}
16+
```

Documentation~/reference.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Reference
2+
3+
This section contains a reference for attributes and classes the Performance Testing Extension supports.
4+
5+
## Test Attributes
6+
**[Performance]** - Use this with `Test` and `UnityTest` attributes. It will initialize necessary test setup for performance tests.
7+
8+
**[Test]** - Non-yielding test. This type of test starts and ends within the same frame.
9+
10+
**[UnityTest]** - Yielding test. This is a good choice if you want to sample measurements across multiple frames. For more on the difference between `[Test]` and `[UnityTest]`, see the Unity Test Framework [documentation](https://docs.unity3d.com/Packages/com.unity.test-framework@1.1/manual/reference-attribute-unitytest.html).
11+
12+
**[Version(string version)]** - Performance tests should be versioned with every change. If not specified, the default used is 1. This is essential when comparing results as results will vary any time the test changes.
13+
14+
15+
## SampleGroup
16+
17+
**class SampleGroup** - represents a group of samples with the same purpose that share a name, sample unit and whether an increase is better.
18+
19+
Optional parameters
20+
- **Name** : Name of the measurement. If unspecified, "Time" is used as the default name.
21+
- **Unit** : Unit of the measurement to report samples in. Possible values are:
22+
Nanosecond, Microsecond, Millisecond, Second, Byte, Kilobyte, Megabyte, Gigabyte
23+
- **IncreaseIsBetter** : If true, an increase in the measurement value is considered a performance improvement (progression). If false, an increase is treated as a performance regression. False by default.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Taking measurements
2+
3+
The Performance Testing Extension provides several API methods for taking measurements in your performance test, depending on what you need to measure and how you want to do it. Include `using Unity.PerformanceTesting` at the top of your script to access the methods.
4+
5+
The pages in this section detail the specifics of each measurement method with examples:
6+
7+
* [Measure.Method](./measure-method.md)
8+
* [Measure.Frames](./measure-frames.md)
9+
* [Measure.Scope](./measure-scope.md)
10+
* [Measure.ProfilerMarkers](./measure-profile-markers.md)
11+
* [Measure.Custom](./measure-custom.md)
12+

0 commit comments

Comments
 (0)