Remove Performance Tests

This commit is contained in:
vis2k 2020-09-27 21:40:31 +02:00
parent 5a8c822683
commit 47c42d870e
19 changed files with 0 additions and 603 deletions

View File

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: e0b34ea3c905e3c42aaf95c1572edb1a
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: 2c40e1b4653f9ca4b928a0ff52f33c60
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,25 +0,0 @@
#if !UNITY_2019_2_OR_NEWER || UNITY_PERFORMANCE_TESTS_1_OR_OLDER
using System;
namespace Mirror.Tests.Performance
{
public class FakeNetworkConnection : NetworkConnectionToClient
{
public FakeNetworkConnection(int networkConnectionId) : base(networkConnectionId)
{
}
public override string address => "Test";
public override void Disconnect()
{
// nothing
}
internal override bool Send(ArraySegment<byte> segment, int channelId = 0)
{
return true;
}
}
}
#endif

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 86a4aabfbe99daa45ad611feea5f959d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,30 +0,0 @@
{
"name": "Mirror.Tests.Performance.Editor",
"references": [
"Unity.PerformanceTesting",
"Mirror",
"Mirror.Components",
"Mirror.Tests.Common"
],
"optionalUnityReferences": [
"TestAssemblies"
],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [
"UNITY_INCLUDE_TESTS"
],
"versionDefines": [
{
"name": "com.unity.test-framework.performance",
"expression": "(,2.0)",
"define": "UNITY_PERFORMANCE_TESTS_1_OR_OLDER"
}
]
}

View File

@ -1,7 +0,0 @@
fileFormatVersion: 2
guid: 6ac82bd0f79158140826224aad56b5e3
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,90 +0,0 @@
#if !UNITY_2019_2_OR_NEWER || UNITY_PERFORMANCE_TESTS_1_OR_OLDER
using NUnit.Framework;
using Unity.PerformanceTesting;
using UnityEngine;
namespace Mirror.Tests.Performance
{
public class Health : NetworkBehaviour
{
[SyncVar] public int health = 10;
public void Update()
{
health = (health + 1) % 10;
}
}
[Category("Performance")]
[Category("Benchmark")]
public class NetworkIdentityPerformance
{
GameObject gameObject;
NetworkIdentity identity;
Health health;
[SetUp]
public void SetUp()
{
gameObject = new GameObject();
identity = gameObject.AddComponent<NetworkIdentity>();
identity.observers = new System.Collections.Generic.Dictionary<int, NetworkConnection>();
identity.connectionToClient = new FakeNetworkConnection(1);
identity.observers.Add(1, identity.connectionToClient);
health = gameObject.AddComponent<Health>();
health.syncMode = SyncMode.Owner;
health.syncInterval = 0f;
}
[TearDown]
public void TearDown()
{
UnityEngine.Object.DestroyImmediate(gameObject);
}
[Test]
#if UNITY_2019_2_OR_NEWER
[Performance]
#else
[PerformanceTest]
#endif
public void NetworkIdentityServerUpdateIsDirty()
{
Measure.Method(RunServerUpdateIsDirty)
.WarmupCount(10)
.MeasurementCount(100)
.Run();
}
void RunServerUpdateIsDirty()
{
for (int j = 0; j < 10000; j++)
{
health.SetDirtyBit(1UL);
identity.ServerUpdate();
}
}
[Test]
#if UNITY_2019_2_OR_NEWER
[Performance]
#else
[PerformanceTest]
#endif
public void NetworkIdentityServerUpdateNotDirty()
{
Measure.Method(RunServerUpdateNotDirty)
.WarmupCount(10)
.MeasurementCount(100)
.Run();
}
void RunServerUpdateNotDirty()
{
for (int j = 0; j < 10000; j++)
{
identity.ServerUpdate();
}
}
}
}
#endif

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 8bf0e9ffea6328a42aac1c6bbfe410ec
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,89 +0,0 @@
#if !UNITY_2019_2_OR_NEWER || UNITY_PERFORMANCE_TESTS_1_OR_OLDER
using NUnit.Framework;
using Unity.PerformanceTesting;
using UnityEngine;
namespace Mirror.Tests.Performance
{
[Category("Performance")]
[Category("Benchmark")]
public class NetworkIdentityPerformanceWithMultipleBehaviour
{
const int healthCount = 32;
GameObject gameObject;
NetworkIdentity identity;
Health[] health;
[SetUp]
public void SetUp()
{
gameObject = new GameObject();
identity = gameObject.AddComponent<NetworkIdentity>();
identity.observers = new System.Collections.Generic.Dictionary<int, NetworkConnection>();
identity.connectionToClient = new FakeNetworkConnection(1);
identity.observers.Add(1, identity.connectionToClient);
health = new Health[healthCount];
for (int i = 0; i < healthCount; i++)
{
health[i] = gameObject.AddComponent<Health>();
health[i].syncMode = SyncMode.Owner;
health[i].syncInterval = 0f;
}
}
[TearDown]
public void TearDown()
{
UnityEngine.Object.DestroyImmediate(gameObject);
}
[Test]
#if UNITY_2019_2_OR_NEWER
[Performance]
#else
[PerformanceTest]
#endif
public void ServerUpdateIsDirty()
{
Measure.Method(RunServerUpdateIsDirty)
.WarmupCount(10)
.MeasurementCount(100)
.Run();
}
void RunServerUpdateIsDirty()
{
for (int j = 0; j < 10000; j++)
{
for (int i = 0; i < healthCount; i++)
{
health[i].SetDirtyBit(1UL);
}
identity.ServerUpdate();
}
}
[Test]
#if UNITY_2019_2_OR_NEWER
[Performance]
#else
[PerformanceTest]
#endif
public void ServerUpdateNotDirty()
{
Measure.Method(RunServerUpdateNotDirty)
.WarmupCount(10)
.MeasurementCount(100)
.Run();
}
void RunServerUpdateNotDirty()
{
for (int j = 0; j < 10000; j++)
{
identity.ServerUpdate();
}
}
}
}
#endif

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: f690766cb23aca74d86925a64b233ca1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,40 +0,0 @@
#if !UNITY_2019_2_OR_NEWER || UNITY_PERFORMANCE_TESTS_1_OR_OLDER
using NUnit.Framework;
using Unity.PerformanceTesting;
namespace Mirror.Tests.Performance
{
[Category("Performance")]
public class NetworkWriterPerformance
{
// A Test behaves as an ordinary method
[Test]
#if UNITY_2019_2_OR_NEWER
[Performance]
#else
[PerformanceTest]
#endif
public void WritePackedInt32()
{
Measure.Method(WriteInt32)
.WarmupCount(10)
.MeasurementCount(100)
.Run();
}
static void WriteInt32()
{
for (int j = 0; j < 1000; j++)
{
using (PooledNetworkWriter writer = NetworkWriterPool.GetWriter())
{
for (int i = 0; i < 10; i++)
{
writer.WritePackedInt32(i * 1000);
}
}
}
}
}
}
#endif

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: a3c833c30b262be45860a01b933a3220
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,71 +0,0 @@
# Performance Tests
Performance tests require `com.unity.test-framework.performance`
#### Install Unity Performance Testing Extension
When using 2019.1 or earlier you have to manually add these to your `manifest.json` or copy from Mirror's `Packages/manifest.json`
- Open `manifest.json`
- Add
```json
{
"dependencies": {
"com.unity.test-framework.performance": "0.1.50-preview",
"other dependencies here"
},
"testables": [
"com.unity.test-framework.performance"
]
}
```
## Run Tests from CLI
[Unity CLI Documentation](https://docs.unity3d.com/2018.4/Documentation/Manual/CommandLineArguments.html)
Options:
- `-testResults` Where results are saved
- `-testPlatform` Use `editmode` or `playmode` to pick which tests to run
- `-testCategory` Comma separated list of test categories
- `-testsFilter` Comma separated list of test names
- `-logFile` change log path, Default path `%LOCALAPPDATA%\Unity\Editor\Editor.log`
Example of running Benchmark tests from cli
```
Unity.exe -testResults /path/to/send/results.xml -runTests -testPlatform playmode -projectPath G:\UnityProjects\Mirror -batchmode -testCategory Benchmark
```
## Create a Performance Benchmark Report
To use Performance Benchmark Reporter you must have:
- [.NET core SDK](https://dotnet.microsoft.com/download)
- [Performance Benchmark Reporter DLL](https://github.com/Unity-Technologies/PerformanceBenchmarkReporter/releases)
- `test-framework.performance` Package at version `0.1.50` or earlier (available Unity versions 2018.3 or 2018.4)
The Performance Benchmark Reporter does not work with newer versions of the test-framework because unity has modified the results XML. The Reporter is open source so it is possible to modify it to work with later versions at some point in the future.
### Run the Performance Benchmark Reporter
1. Run the performance tests to create a `TestResults.xml`
2. If running from editor, move the generated `TestResults.xml` file
3. Change branches and run performance tests again
4. Once all results are collected run the Performance Benchmark Reporter DLL
5. Open the "UnityPerformanceBenchmark" html file that is created to view the report
```
dotnet UnityPerformanceBenchmarkReporter.dll --baseline=D:\UnityPerf\baseline.xml --results=D:\UnityPerf\results --reportdirpath=d:\UnityPerf
```
## Links
#### Blog post
<https://blogs.unity3d.com/2018/09/25/performance-benchmarking-in-unity-how-to-get-started/>
#### Unity packages
<https://docs.unity3d.com/Packages/com.unity.test-framework.performance@0.1/manual/index.html>
#### Performance Benchmark Reporter
<https://github.com/Unity-Technologies/PerformanceBenchmarkReporter/wiki>

View File

@ -1,7 +0,0 @@
fileFormatVersion: 2
guid: a322196416f669044b8d2fa186a6f80c
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: 5f902e7dc9ebba44fa9ed637a824ddb8
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,29 +0,0 @@
{
"name": "Mirror.Tests.Performance.Runtime",
"references": [
"Unity.PerformanceTesting",
"Mirror",
"Mirror.Components",
"Mirror.Tests.Common",
"Mirror.Examples"
],
"optionalUnityReferences": [
"TestAssemblies"
],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [
"UNITY_INCLUDE_TESTS"
],
"versionDefines": [
{
"name": "com.unity.test-framework.performance",
"expression": "(,2.0)",
"define": "UNITY_PERFORMANCE_TESTS_1_OR_OLDER"
}
]
}

View File

@ -1,7 +0,0 @@
fileFormatVersion: 2
guid: 98f4e20eb641b974bab6c080624bb1ae
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,129 +0,0 @@
#if !UNITY_2019_2_OR_NEWER || UNITY_PERFORMANCE_TESTS_1_OR_OLDER
using System.Collections;
using NUnit.Framework;
using Unity.PerformanceTesting;
using UnityEngine;
using UnityEngine.TestTools;
namespace Mirror.Tests.Performance.Runtime
{
class NetworkManagerTest : NetworkManager
{
public override void Awake()
{
transport = gameObject.AddComponent<MemoryTransport>();
playerPrefab = new GameObject();
NetworkIdentity identity = playerPrefab.AddComponent<NetworkIdentity>();
identity.assetId = System.Guid.NewGuid();
base.Awake();
}
public override void OnDestroy()
{
base.OnDestroy();
// clean up new object created in awake
Destroy(playerPrefab);
}
}
[Category("Performance")]
public class ULocalConnectionPerformance
{
NetworkManager manager;
IEnumerator SetUpConnections()
{
GameObject go = new GameObject();
manager = go.AddComponent<NetworkManagerTest>();
yield return null;
manager.StartHost();
yield return null;
}
IEnumerator Disconnect()
{
manager.StopHost();
yield return null;
GameObject.Destroy(manager.gameObject);
}
[OneTimeTearDown]
public void OneTimeTearDown()
{
if (NetworkManager.singleton != null)
{
GameObject go = NetworkManager.singleton.gameObject;
NetworkManager.Shutdown();
GameObject.DestroyImmediate(go);
}
}
[UnityTest]
public IEnumerator ConnectAndDisconnectWorks()
{
yield return SetUpConnections();
yield return Disconnect();
}
[UnityTest]
#if UNITY_2019_2_OR_NEWER
[Performance]
#else
[PerformanceUnityTest]
#endif
public IEnumerator ULocalConnectionPerformanceWithEnumeratorPasses()
{
yield return SetUpConnections();
using (Measure.Frames()
.WarmupCount(10)
.MeasurementCount(100)
.Scope())
{
for (int i = 0; i < 100; i++)
{
sendSomeMessages();
yield return null;
}
}
yield return Disconnect();
}
static void sendSomeMessages()
{
for (uint i = 0; i < 10000u; i++)
{
using (PooledNetworkWriter writer = NetworkWriterPool.GetWriter())
{
// write mask
writer.WritePackedUInt64(1);
// behaviour length
writer.WriteInt32(1);
// behaviour delta
// sync object mask
writer.WritePackedUInt64(0);
// sync object delta
// assume no sync objects for this test
// sync var mask
writer.WritePackedUInt64(1);
// sync var delta
// assume sync var has changed its value to 10
writer.WritePackedInt32(10);
// send message
NetworkServer.localConnection.Send(new UpdateVarsMessage
{
netId = i,
payload = writer.ToArraySegment()
});
}
}
}
}
}
#endif

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 82f7edc4e79efb74db284b02dab6704d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: