Skip to content

Instantly share code, notes, and snippets.

@rzubek
Created June 16, 2014 21:49
Show Gist options
  • Save rzubek/ee76f08290624cf8c6f7 to your computer and use it in GitHub Desktop.
Save rzubek/ee76f08290624cf8c6f7 to your computer and use it in GitHub Desktop.
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