Skip to content

Instantly share code, notes, and snippets.

@dkoontz
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dkoontz/bc412e7fd7a1edd02142 to your computer and use it in GitHub Desktop.
Save dkoontz/bc412e7fd7a1edd02142 to your computer and use it in GitHub Desktop.
Microbenchmark test for MonoBehavior vs RobotArms Component + Processor
2 prefabs consisting of the default Unity cube were created, each with 1 of the two scripts attached. A test harness then instantiated 1000 of each cube at the origin.
Profiler results:
Overview Total Self Calls GC Alloc Time ms Self ms
----------------------------------------------------------------------------------------------------------
Camera.Render 44.0% 0.2% 1 0B 6.47 0.03
BehaviourUpdate 42.6% 6.0% 1 160B 6.27 0.88
- MonoBehaviourJiggle.Update() 18.6% 17.9% 1000 0B 2.74 2.64
- RobotArmsCoordinator.Update() 18.0% 17.7% 1 160B 2.64 2.61
Physics.Processing 5.4% 0.3% 1 0B 0.79 0.04
using UnityEngine;
public class MonoBehaviourJiggle : MonoBehaviour {
public Vector3 Amount;
void Update () {
transform.Translate(new Vector3(
Amount.x * Random.Range(-1, 1),
Amount.y * Random.Range(-1, 1),
Amount.z * Random.Range(-1, 1)
));
}
}
using UnityEngine;
using RobotArms;
public class RobotArmsJiggle : RobotArmsComponent {
public Vector3 Amount;
}
using UnityEngine;
using RobotArms;
[ProcessorOptions(typeof(RobotArmsJiggle))]
public class RobotArmsJiggleProcessor : RobotArmsProcessor {
public override void Process(GameObject entity) {
var component = entity.GetComponent<RobotArmsJiggle>();
component.transform.Translate(new Vector3(
component.Amount.x * Random.Range(-1, 1),
component.Amount.y * Random.Range(-1, 1),
component.Amount.z * Random.Range(-1, 1)
));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment