Skip to content

Commit 3f9805e

Browse files
author
Unity Technologies
committed
com.unity.test-framework.performance@2.3.1-preview
## [2.3.1] - 2020-07-01 Fix overhead introduced with Measure.Method no longer calculates execution time of Setup and Cleanup changes ## [2.3.0] - 2020-06-17 Fix Measure.Method overhead Measure.Method no longer caclulates execution time of Setup and Cleanup Overwritten test name will be displyed with method name in Test Result viewer ## [2.2.0] - 2020-05-26 Add support for custom metadata
1 parent 7b874b9 commit 3f9805e

File tree

9 files changed

+204
-16
lines changed

9 files changed

+204
-16
lines changed

CHANGELOG.md

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

3+
## [2.3.1] - 2020-07-01
4+
5+
Fix overhead introduced with Measure.Method no longer calculates execution time of Setup and Cleanup changes
6+
7+
## [2.3.0] - 2020-06-17
8+
9+
Fix Measure.Method overhead
10+
Measure.Method no longer caclulates execution time of Setup and Cleanup
11+
Overwritten test name will be displyed with method name in Test Result viewer
12+
313
## [2.2.0] - 2020-05-26
414

515
Add support for custom metadata

Documentation~/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ The Performance Testing Extension is intended to be used with, and complement, t
1111

1212
To install the Performance Testing Extension package
1313
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.2.0-preview",` to the dependencies
14+
2. Add `"com.unity.test-framework.performance": "2.3.1-preview",` to the dependencies
1515
3. Save the manifest.json file
1616
4. Verify the Performance Testing Extension is now installed opening the Unity Package Manager window
1717

LICENSE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
com.unity.test-framework.performance copyright © 2019 Unity Technologies ApS
1+
com.unity.test-framework.performance copyright © 2020 Unity Technologies ApS
22

33
Licensed under the Unity Companion License for Unity-dependent projects--see [Unity Companion License](http://www.unity3d.com/legal/licenses/Unity_Companion_License).
44

Runtime/Measurements/MethodMeasurement.cs

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public MethodMeasurement(Action action)
3131
{
3232
m_Action = action;
3333
m_GCRecorder = Recorder.Get("GC.Alloc");
34+
m_GCRecorder.enabled = false;
3435
m_Watch = Stopwatch.StartNew();
3536
}
3637

@@ -155,8 +156,8 @@ private int Probing()
155156

156157
if (iterations == 1)
157158
{
158-
ExecuteActionWithCleanupWarmup();
159-
ExecuteActionWithCleanupWarmup();
159+
ExecuteActionWithCleanupSetup();
160+
ExecuteActionWithCleanupSetup();
160161

161162
return 1;
162163
}
@@ -171,15 +172,19 @@ private void Warmup(int iterations)
171172
{
172173
for (var i = 0; i < iterations; i++)
173174
{
174-
ExecuteActionWithCleanupWarmup();
175+
ExecuteActionWithCleanupSetup();
175176
}
176177
}
177178

178-
private void ExecuteActionWithCleanupWarmup()
179+
private double ExecuteActionWithCleanupSetup()
179180
{
180181
m_Setup?.Invoke();
182+
var executionTime = m_Watch.Elapsed.TotalMilliseconds;
181183
m_Action.Invoke();
184+
executionTime = m_Watch.Elapsed.TotalMilliseconds - executionTime;
182185
m_Cleanup?.Invoke();
186+
187+
return executionTime;
183188
}
184189

185190
private double ExecuteSingleIteration()
@@ -199,13 +204,25 @@ private double ExecuteSingleIteration()
199204
private double ExecuteForIterations(int iterations)
200205
{
201206
if (m_GC) StartGCRecorder();
202-
var executionTime = m_Watch.Elapsed.TotalMilliseconds;
203-
for (var i = 0; i < iterations; i++)
207+
var executionTime = 0.0D;
208+
209+
if (m_Cleanup != null || m_Setup != null)
210+
{
211+
for (var i = 0; i < iterations; i++)
212+
{
213+
executionTime += ExecuteActionWithCleanupSetup();
214+
}
215+
}
216+
else
204217
{
205-
ExecuteActionWithCleanupWarmup();
218+
executionTime = m_Watch.Elapsed.TotalMilliseconds;
219+
for (var i = 0; i < iterations; i++)
220+
{
221+
m_Action.Invoke();
222+
}
223+
executionTime = m_Watch.Elapsed.TotalMilliseconds - executionTime;
206224
}
207-
208-
executionTime = m_Watch.Elapsed.TotalMilliseconds - executionTime;
225+
209226
if (m_GC) EndGCRecorderAndMeasure(iterations);
210227
return executionTime;
211228
}

Runtime/PerformanceTest.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,15 @@ internal static void StartTest(ITest currentTest)
5050
go.hideFlags = HideFlags.HideAndDontSave;
5151
var performanceTestHelper = go.AddComponent<PerformanceTestHelper>();
5252

53+
string methodName = currentTest.Name.Contains("(")
54+
? currentTest.Name.Remove(currentTest.Name.IndexOf("(", StringComparison.Ordinal))
55+
: currentTest.Name;
56+
57+
var fullName = currentTest.MethodName != methodName ? $"{currentTest.ClassName}.{currentTest.MethodName}.{currentTest.Name}" : currentTest.FullName;
58+
5359
var test = new PerformanceTest
5460
{
55-
Name = currentTest.FullName,
61+
Name = fullName,
5662
Categories = currentTest.GetAllCategoriesFromTest(),
5763
Version = GetVersion(currentTest),
5864
m_PerformanceTestHelper = performanceTestHelper
@@ -81,7 +87,6 @@ private static string GetVersion(ITest currentTest)
8187
internal static void EndTest(ITest test)
8288
{
8389
if (test.IsSuite) return;
84-
if (test.FullName != Active.Name) return;
8590

8691
if (Active.m_PerformanceTestHelper != null && Active.m_PerformanceTestHelper.gameObject != null)
8792
UnityEngine.Object.DestroyImmediate(Active.m_PerformanceTestHelper.gameObject);

Tests/Editor/MeasureMethodTests.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,34 @@ public void MeasureMethod_SetupCleanup_Run()
4343
Assert.AreEqual(test.SampleGroups[0].Samples.Count, 10);
4444
Assert.AreEqual(30, s_CallCount);
4545
}
46+
47+
[Test, Performance]
48+
public void MeasureMethod_Setup_Run()
49+
{
50+
s_CallCount = 0;
51+
Measure.Method(() => { })
52+
.MeasurementCount(10)
53+
.SetUp(() => s_CallCount++)
54+
.Run();
55+
56+
var test = PerformanceTest.Active;
57+
Assert.AreEqual(test.SampleGroups[0].Samples.Count, 10);
58+
Assert.AreEqual(10, s_CallCount);
59+
}
60+
61+
[Test, Performance]
62+
public void MeasureMethodCleanup_Run()
63+
{
64+
s_CallCount = 0;
65+
Measure.Method(() => { })
66+
.MeasurementCount(10)
67+
.CleanUp(() => s_CallCount++)
68+
.Run();
69+
70+
var test = PerformanceTest.Active;
71+
Assert.AreEqual(test.SampleGroups[0].Samples.Count, 10);
72+
Assert.AreEqual(10, s_CallCount);
73+
}
4674

4775
[Test, Performance]
4876
public void MeasureMethod_MeasurementAndIterationCount_Run()
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
using System;
2+
using System.Collections;
3+
using NUnit.Framework;
4+
using Unity.PerformanceTesting;
5+
using UnityEngine.TestTools;
6+
7+
namespace TestNameOverwrite
8+
{
9+
public class TestNameOverwriteInNamespaceTests
10+
{
11+
[Test, Performance]
12+
public void TestName_NameSpace_Default()
13+
{
14+
Assert.AreEqual(PerformanceTest.Active.Name,$"TestNameOverwrite.TestNameOverwriteInNamespaceTests.TestName_NameSpace_Default");
15+
}
16+
17+
[Performance, TestCase(TestName = "TestName_OverwriteInTestCase")]
18+
public void TestName_Overwrite_TestCase()
19+
{
20+
Assert.AreEqual(PerformanceTest.Active.Name, "TestNameOverwrite.TestNameOverwriteInNamespaceTests.TestName_Overwrite_TestCase.TestName_OverwriteInTestCase");
21+
}
22+
}
23+
}
24+
25+
public class TestNameOverwriteTests
26+
{
27+
private static int[] integer = new int[] {2};
28+
29+
[Performance]
30+
[TestCase(1)]
31+
[TestCaseSource(nameof(integer))]
32+
public void TestName_TestCase_Default(int n)
33+
{
34+
Assert.AreEqual(PerformanceTest.Active.Name,$"TestNameOverwriteTests.TestName_TestCase_Default({n})");
35+
}
36+
37+
[Performance, TestCase(TestName = "TestName_OverwriteInTestCase")]
38+
public void TestName_Overwrite_TestCase()
39+
{
40+
Assert.AreEqual(PerformanceTest.Active.Name, "TestNameOverwriteTests.TestName_Overwrite_TestCase.TestName_OverwriteInTestCase");
41+
}
42+
43+
[Performance, TestCaseSource(typeof(MyFactoryClass),"TestCases")]
44+
public void TestName_Overwrite_TestCaseSource()
45+
{
46+
Assert.AreEqual(PerformanceTest.Active.Name, "TestNameOverwriteTests.TestName_Overwrite_TestCaseSource.TestName_OverwriteInTestCaseSource");
47+
}
48+
49+
[Test, Performance]
50+
public void TestName_OverwriteMethodName( [ValueSource(nameof(MethodWrapper))] TestWrapper wrapper)
51+
{
52+
Assert.AreEqual(PerformanceTest.Active.Name, "TestNameOverwriteTests.TestName_OverwriteMethodName(OverwriteTestMethodName)");
53+
}
54+
55+
[UnityTest, Performance]
56+
[TestCase(1)]
57+
[TestCaseSource(nameof(integer))]
58+
public void TestName_TestCase_Default_UnityTest(int n)
59+
{
60+
Assert.AreEqual(PerformanceTest.Active.Name,$"TestNameOverwriteTests.TestName_TestCase_Default_UnityTest({n})");
61+
}
62+
63+
[Performance, TestCase(TestName = "TestName_OverwriteInTestCase")]
64+
public void TestName_Overwrite_TestCase_UnityTest()
65+
{
66+
Assert.AreEqual(PerformanceTest.Active.Name, "TestNameOverwriteTests.TestName_Overwrite_TestCase_UnityTest.TestName_OverwriteInTestCase");
67+
}
68+
69+
[Performance, TestCaseSource(typeof(MyFactoryClass),"TestCases")]
70+
public void TestName_Overwrite_TestCaseSource_UnityTest()
71+
{
72+
Assert.AreEqual(PerformanceTest.Active.Name, "TestNameOverwriteTests.TestName_Overwrite_TestCaseSource_UnityTest.TestName_OverwriteInTestCaseSource");
73+
}
74+
75+
[Test, Performance]
76+
public void TestName_OverwriteMethodName_UnityTest( [ValueSource(nameof(MethodWrapper))] TestWrapper wrapper)
77+
{
78+
Assert.AreEqual(PerformanceTest.Active.Name, "TestNameOverwriteTests.TestName_OverwriteMethodName_UnityTest(OverwriteTestMethodName)");
79+
}
80+
81+
public struct TestWrapper
82+
{
83+
private Func<String> func;
84+
85+
public TestWrapper(Func<String> func)
86+
{
87+
this.func = func;
88+
}
89+
90+
public override string ToString()
91+
{
92+
return "OverwriteTestMethodName";
93+
}
94+
}
95+
96+
private static TestWrapper[] MethodWrapper =
97+
{
98+
new TestWrapper(TestMethod),
99+
};
100+
101+
private static String TestMethod()
102+
{
103+
return "TestMethod";
104+
}
105+
}
106+
107+
public class MyFactoryClass
108+
{
109+
public static IEnumerable TestCases
110+
{
111+
get
112+
{
113+
yield return new TestCaseData()
114+
.SetName("TestName_OverwriteInTestCaseSource");
115+
}
116+
}
117+
}

Tests/Editor/TestNameOverwriteTests.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "com.unity.test-framework.performance",
33
"displayName": "Performance testing API",
4-
"version": "2.2.0-preview",
4+
"version": "2.3.1-preview",
55
"unity": "2019.3",
66
"unityRelease": "0a10",
77
"description": "Extension to the Unity Test framework package. Adds performance testing capabilities and collects configuration metadata.",
@@ -14,11 +14,11 @@
1414
"com.unity.nuget.newtonsoft-json": "2.0.0-preview"
1515
},
1616
"upmCi": {
17-
"footprint": "acdb45aa0381a84a127b5bc4b1aecb5abcc7b142"
17+
"footprint": "6785338b363ed02bc9d3dd6366b7f643ff55b789"
1818
},
1919
"repository": {
2020
"url": "https://github.cds.internal.unity3d.com/unity/com.unity.test-framework.performance.git",
2121
"type": "git",
22-
"revision": "1d0ef47bac7a18f1c14da1ee42082ae030273971"
22+
"revision": "f3bcc9ec6b911cc61eed160ca116d7fa33ae4b0a"
2323
}
2424
}

0 commit comments

Comments
 (0)