Skip to content

Instantly share code, notes, and snippets.

@ahmadnaser
Created February 3, 2016 14:25
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 ahmadnaser/74ae5aaa4a03ca11aa94 to your computer and use it in GitHub Desktop.
Save ahmadnaser/74ae5aaa4a03ca11aa94 to your computer and use it in GitHub Desktop.
using UnityEngine;
using System.Collections;
public class LevelLoader : MonoBehaviour
{
public int calculations = 10000;
public int iterations = 10000;
public bool inAwake = true;
public bool inStart = true;
IEnumerator Start ()
{
if (inStart == true) {
Calculate ("Start");
}
AsyncOperation async = Application.LoadLevelAsync ("Menu");
yield return async;
Debug.Log ("Loading complete");
}
void Awake ()
{
if (inAwake == true) {
Calculate ("Awake");
}
}
string debugText = "Calculating...";
private void Calculate (string funcName)
{
System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch ();
stopwatch.Start ();
Vector3 calc = Vector3.zero;
// Do some random calculations:
for (int i = 0; i < iterations; i++) {
calc = Vector3.zero;
for (int c = 0; c < calculations; c++) {
calc = calc + Random.onUnitSphere;
}
}
stopwatch.Stop ();
Debug.Log (stopwatch.Elapsed);
debugText += "\n" + funcName + ": " + stopwatch.Elapsed.ToString ();
}
private void OnGUI ()
{
GUILayout.BeginVertical ("box");
GUILayout.Label (debugText);
GUILayout.EndVertical ();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment