Skip to content

Instantly share code, notes, and snippets.

@Kryeker
Forked from chuckbergeron/CompileTime.cs
Created September 16, 2022 23:39
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 Kryeker/4db55a7b2a186306c357b18a3bf9ce9b to your computer and use it in GitHub Desktop.
Save Kryeker/4db55a7b2a186306c357b18a3bf9ce9b to your computer and use it in GitHub Desktop.
Unity Measure Compile Time
# // Originally found here: https://answers.unity.com/questions/1131497/how-to-measure-the-amount-of-time-it-takes-for-uni.html
using UnityEngine;
using UnityEditor;
[InitializeOnLoad]
class CompileTime : EditorWindow
{
static bool isTrackingTime;
static double startTime;
static CompileTime()
{
EditorApplication.update += Update;
startTime = PlayerPrefs.GetFloat("CompileStartTime", 0);
if (startTime > 0)
{
isTrackingTime = true;
}
}
static void Update()
{
if (EditorApplication.isCompiling && !isTrackingTime)
{
startTime = EditorApplication.timeSinceStartup;
PlayerPrefs.SetFloat("CompileStartTime", (float)startTime);
isTrackingTime = true;
}
else if (!EditorApplication.isCompiling && isTrackingTime)
{
var finishTime = EditorApplication.timeSinceStartup;
isTrackingTime = false;
var compileTime = finishTime - startTime;
PlayerPrefs.DeleteKey("CompileStartTime");
Debug.Log("Script compilation time: \n" + compileTime.ToString("0.000") + "s");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment