Created
April 7, 2016 15:04
-
-
Save gcusso/46499306a7175c7acb0946acfcc7e2ed to your computer and use it in GitHub Desktop.
Class to measure time spend in code in a Unity Project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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