Skip to content

Instantly share code, notes, and snippets.

@nicloay
Last active October 29, 2015 11:24
Show Gist options
  • Select an option

  • Save nicloay/11f47765e2c3622f2507 to your computer and use it in GitHub Desktop.

Select an option

Save nicloay/11f47765e2c3622f2507 to your computer and use it in GitHub Desktop.
performance
using UnityEngine;
using System.Collections;
public class Test : MonoBehaviour {
int arraySize = 1024*2048;
string status = "unknown";
float avgFPSIn = 0.0f;
float avgFpsOut = 0.0f;
float fps = 0.0f;
// Update is called once per frame
void Update () {
fps = 1.0f / Time.deltaTime;
if (Mathf.PingPong( Time.timeSinceLevelLoad, 4.0f) > 2.0f) {
status = "in";
avgFPSIn = (avgFPSIn + fps) / 2.0f;
InCycle ();
} else {
status = "out";
avgFpsOut = (avgFpsOut + fps) / 2.0f;
OutOfCycle();
}
}
Vector2 result = Vector3.zero;
void OnGUI(){
GUILayout.TextField (status);
GUILayout.TextField("fps = "+fps);
GUILayout.TextField ("avg in = " + avgFPSIn);
GUILayout.TextField("avg out = " + avgFpsOut);
}
void InCycle(){
for (int i = 0; i < arraySize; i++) {
Vector3 a = new Vector3(0,0,0);
Vector3 b = new Vector3(1,1,1);
Vector3 c = a + b;
result = c;
}
}
void OutOfCycle(){
Vector3 a, b, c;
for (int i = 0; i < arraySize; i++) {
a.x = 0.0f;
a.y = 0.0f;
a.z = 0.0f;
b.x = 1.0f;
b.y = 1.0f;
b.z = 1.0f;
c = a + b;
result = c;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment