You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
## [2.1.0] - 2020-05-14
Add flexible horizontal splitter for report window
Fix date format
## [2.0.9] - 2020-03-23
Fix profiler measurements for method measurements
Throw exceptions when measuring NaN
Copy file name to clipboardExpand all lines: Documentation~/index.md
+126-1Lines changed: 126 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,7 @@ The Performance Testing Extension is intended to be used with, and complement, t
11
11
12
12
To install the Performance Testing Extension package
13
13
1. Open the `manifest.json` file for your Unity project (located in the YourProject/Packages directory) in a text editor
14
-
2. Add `"com.unity.test-framework.performance": "2.0.9-preview",` to the dependencies
14
+
2. Add `"com.unity.test-framework.performance": "2.1.0-preview",` to the dependencies
15
15
3. Save the manifest.json file
16
16
4. Verify the Performance Testing Extension is now installed opening the Unity Package Manager window
17
17
@@ -334,6 +334,131 @@ public static string GetScenePath(string name)
334
334
}
335
335
```
336
336
337
+
## Writing a simple test
338
+
339
+
As an example, to measure the performance of Vector2 operations you can use `Measure.Method`. This executes the provided method and samples performance. You can increase `MeasurementCount` from the default of 7 to 20 to achieve better performance test stability. You can execute a `Vector2.MoveTowards` test in Edit or Play mode.
340
+
341
+
```csharp
342
+
[Test, Performance]
343
+
publicvoidVector2_operations()
344
+
{
345
+
vara=Vector2.one;
346
+
varb=Vector2.zero;
347
+
348
+
Measure.Method(() =>
349
+
{
350
+
Vector2.MoveTowards(a, b, 0.5f);
351
+
Vector2.ClampMagnitude(a, 0.5f);
352
+
Vector2.Reflect(a, b);
353
+
Vector2.SignedAngle(a, b);
354
+
})
355
+
.MeasurementCount(20)
356
+
.Run();
357
+
}
358
+
```
359
+
360
+
To view the results, go to **Window > Analysis > Performance Test Report**.
361
+
362
+

363
+
364
+
In this example, the results show that the first method execution took five times longer than the subsequent methods, and those subsequent method executions were unstable. Also, you can’t tell from these test results how long it took for each Vector2 operation to execute.
365
+
366
+
### Improving test stability
367
+
368
+
You can improve this test in several ways. First, try to improve test stability. Test instability at the beginning of a test can occur for several reasons, such as entering Play mode or method initialization, because the tested method is quite fast and more sensitive to other running background processes. To improve this, add `WarmupCount(n)`. This allows you to execute methods before you start to record data, so Unity doesn’t record method initialization. The simplest way to increase test execution time is to repeat the method in a loop.
369
+
Avoid having measurements that are less than 1ms because they are usually more sensitive to unstable environments.
370
+
To help you track each operation's execution times, split the Vector2 operations into several tests. Usually, when writing a test, you use setup and clean up methods to isolate the test environment. However, in this case, methods are isolated and do not affect other methods, therefore they do not need a cleanup or setup.
371
+
The following code example shows a performance test for the `Vector2.MoveTowards` operation. Other Vector2 performance tests are identical.
With 100000 iterations in this test, there is a small fluctuation in method execution time, but the standard deviation is low, which means the test is reasonably stable.
390
+
391
+

392
+
393
+
As an example, if you want to measure a method that only runs in Play mode (for example `Physics.Raycast`), you can use `Measure.Frames()`, which records time per frame by default. To only measure `Physics.Raycast` time, you can disable frame time measurements with `DontRecordFrametime` and just measure the `Physics.Raycast` profiler marker.
394
+
This test creates objects that you need to dispose of at the end of each test, because multiple unnecessary objects can affect the next test results. Use the SetUp method to create GameObjects, and the TearDown method to destroy the created GameObjects after each test.
To record your own measurements, create a new sample group and record a custom metric. The following examples measures `Allocated` and `Reserved` memory.
Before you start to collect package performance data, make sure that the tests you run locally are stable (the data set deviation is <5%). In the **Performance Test Report** window check whether the test isn’t fluctuating and that the results between runs are similar.
458
+
459
+
Performance test results run on a local machine can be significantly different compared to previous test runs because there could be other applications running in the background, or CPU overheating or CPU boosting is enabled. Make sure that CPU intensive applications are turned off where possible. You can disable CPU boost in the BIOS or by using third-parties software, such as Real Temp.
460
+
461
+
For compairing performance data between runs use [Unity Performance Benchmark Reporter](https://github.com/Unity-Technologies/PerformanceBenchmarkReporter/wiki). Unity Performance Benchmark Reporter provides you with a graphical HTML report that enables you to compare performance metric baselines and subsequent performance metrics.
0 commit comments