Skip to content

Commit

Permalink
test cases updated
Browse files Browse the repository at this point in the history
  • Loading branch information
arty-F committed May 24, 2024
1 parent f9df670 commit 56e45ce
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 37 deletions.
45 changes: 45 additions & 0 deletions Assets/MonoInjectorTestScripts/PerformanceTester.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using MonoInjector;
using MonoInjector.Test;
using System.Collections.Generic;
using System.Diagnostics;
using UnityEngine;

namespace Assets.MonoInjectorTestScripts
{
public class PerformanceTester : MonoBehaviour
{
public void Test(
List<FieldsConsumer> fieldsConsumers,
List<PropertiesConsumer> properiesConsumers,
List<MethodConsumer> methodConsumers,
List<AllConsumer> allConsumers,
Stopwatch timer)
{
timer = new Stopwatch();
timer.Start();

foreach (var item in fieldsConsumers)
{
item.Resolve();
}

foreach (var item in properiesConsumers)
{
item.Resolve();
}

foreach (var item in methodConsumers)
{
item.Resolve();
}

foreach (var item in allConsumers)
{
item.Resolve();
}

timer.Stop();
UnityEngine.Debug.Log($"Resolved in {timer.ElapsedMilliseconds} ms.");
}
}
}
2 changes: 2 additions & 0 deletions Assets/MonoInjectorTestScripts/PerformanceTester.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

55 changes: 21 additions & 34 deletions Assets/MonoInjectorTestScripts/Usage.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Collections.Generic;
using Assets.MonoInjectorTestScripts;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using UnityEngine;
Expand All @@ -17,7 +19,14 @@ public class Usage : MonoBehaviour
private bool _methodConsumer;
[SerializeField]
private bool _allConsumer;
[SerializeField]
private PerformanceTester _tester;

private List<FieldsConsumer> _fieldsConsumers;
private List<PropertiesConsumer> _properiesConsumers;
private List<MethodConsumer> _methodConsumers;
private List<AllConsumer> _allConsumers;
private Stopwatch _stopwatch;

private void Start()
{
Expand All @@ -30,49 +39,27 @@ private void Start()
injected3.Inject();
injected4.Inject();

var _fieldsConsumers = _fieldsConsumer
_fieldsConsumers = _fieldsConsumer
? Enumerable.Repeat(new FieldsConsumer(), _instancesCount).ToList()
: new List<FieldsConsumer>();
var _properiesConsumers = _propertiesConsumer
_properiesConsumers = _propertiesConsumer
? Enumerable.Repeat(new PropertiesConsumer(), _instancesCount).ToList()
: new List<PropertiesConsumer>();
var _methodConsumers = _methodConsumer
_methodConsumers = _methodConsumer
? Enumerable.Repeat(new MethodConsumer(), _instancesCount).ToList()
: new List<MethodConsumer>();
var _allConsumers = _allConsumer
_allConsumers = _allConsumer
? Enumerable.Repeat(new AllConsumer(), _instancesCount).ToList()
: new List<AllConsumer>();
_stopwatch = new Stopwatch();

Stopwatch timer = new Stopwatch();
int accumulator = 0;
timer.Start();

foreach (var item in _fieldsConsumers)
{
item.Resolve();
accumulator += item.GetSumField();
}

foreach (var item in _properiesConsumers)
{
item.Resolve();
accumulator += item.GetSumProp();
}

foreach (var item in _methodConsumers)
{
item.Resolve();
accumulator += item.GetSumMethod();
}

foreach (var item in _allConsumers)
{
item.Resolve();
accumulator += item.GetSumAll();
}
StartCoroutine(WaitFrameAndDoTest());
}

timer.Stop();
UnityEngine.Debug.Log($"{accumulator} accumulated in: {timer.ElapsedMilliseconds} ms." );
private IEnumerator WaitFrameAndDoTest()
{
yield return null;
_tester.Test(_fieldsConsumers, _properiesConsumers, _methodConsumers, _allConsumers, _stopwatch);
}
}
}
20 changes: 17 additions & 3 deletions Assets/Scenes/SampleScene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ GameObject:
- component: {fileID: 1249362804}
- component: {fileID: 1249362805}
- component: {fileID: 1249362806}
- component: {fileID: 1249362807}
m_Layer: 0
m_Name: GameObject
m_TagString: Untagged
Expand Down Expand Up @@ -269,10 +270,23 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
_instancesCount: 100
_fieldsConsumer: 1
_fieldsConsumer: 0
_propertiesConsumer: 1
_methodConsumer: 1
_allConsumer: 1
_methodConsumer: 0
_allConsumer: 0
_tester: {fileID: 1249362807}
--- !u!114 &1249362807
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1249362802}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 6bbb3aabdd04b3346be08afa7cff0bdd, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1660057539 &9223372036854775807
SceneRoots:
m_ObjectHideFlags: 0
Expand Down

0 comments on commit 56e45ce

Please sign in to comment.