Skip to content

Instantly share code, notes, and snippets.

@gcusso
Created April 7, 2016 15:04
Show Gist options
  • Save gcusso/46499306a7175c7acb0946acfcc7e2ed to your computer and use it in GitHub Desktop.
Save gcusso/46499306a7175c7acb0946acfcc7e2ed to your computer and use it in GitHub Desktop.
Class to measure time spend in code in a Unity Project
using UnityEngine;
public class Watch
{
private double startTime;
private double endTime;
public Watch()
{
Start ();
}
public void Start()
{
startTime = Time.realtimeSinceStartup;
endTime = 0;
}
public void Stop()
{
endTime = Time.realtimeSinceStartup;
}
/// <summary>
/// Gets the elapsed time in miliseconds.
/// </summary>
public int GetElapsedTime()
{
Stop();
return(int) ((endTime - startTime) * 1000);
}
public void LogElapsedTime(string name)
{
Debug.LogWarning(name + GetElapsedTime() + "ms");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment