Created
June 16, 2014 21:49
-
-
Save rzubek/ee76f08290624cf8c6f7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections; | |
using System.Collections.Generic; | |
using System.Diagnostics; | |
using UnityEngine; | |
namespace Benchmark.Test | |
{ | |
class InstanceSpawner : MonoBehaviour | |
{ | |
int numComponents = 5; | |
int numObjects = 0; | |
List<GameObject> _objects = new List<GameObject>(); | |
public void Start() | |
{ | |
StartCoroutine(SpawnInstances()); | |
} | |
IEnumerator SpawnInstances() | |
{ | |
yield return new WaitForSeconds(1); | |
numObjects = 5000; | |
yield return new WaitForSeconds(3); | |
PrintStatus(); | |
numObjects = 10000; | |
yield return new WaitForSeconds(3); | |
PrintStatus(); | |
numObjects = 15000; | |
yield return new WaitForSeconds(3); | |
PrintStatus(); | |
numObjects = 20000; | |
yield return new WaitForSeconds(3); | |
PrintStatus(); | |
UnityEngine.Debug.Log("DONE"); | |
} | |
void Update() | |
{ | |
while (_objects.Count < numObjects) { SpawnObject(); } | |
} | |
void SpawnObject() | |
{ | |
GameObject obj = new GameObject(); | |
for (int i = 0; i < numComponents; i++) | |
{ | |
obj.AddComponent<DummyComponent>(); | |
} | |
_objects.Add(obj); | |
} | |
void PrintStatus() | |
{ | |
UnityEngine.Debug.Log("ENTITIES: " + _objects.Count + " COMPONENTS: " + numComponents + " FPS: " + HUDFPS.lastFps); | |
} | |
} | |
class DummyComponent : MonoBehaviour | |
{ | |
long updates; | |
void Start() | |
{ | |
this.updates = 0; | |
} | |
void Update() | |
{ | |
this.updates++; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment