Skip to content

Instantly share code, notes, and snippets.

@instance-id
Created August 11, 2019 02:52
Show Gist options
  • Save instance-id/9f8f4d5146440f64e780b0585b073671 to your computer and use it in GitHub Desktop.
Save instance-id/9f8f4d5146440f64e780b0585b073671 to your computer and use it in GitHub Desktop.
Simple compilation time for Unity. Just pop it into an Editor folder and it should give you a simple output of how long it took to compile your code each time.
using System;
using UnityEngine;
using UnityEditor;
namespace instance.id.Editor
{
[InitializeOnLoad]
class CompilationTimer : EditorWindow
{
static bool isTrackingTime;
static double startTime;
static CompilationTimer()
{
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");
var timeStamp = DateTime.Now.ToString("hh:mm:ss");
Debug.Log("Script compilation length: " + compileTime.ToString("0.000") + "s\n" +
"Current time: " + timeStamp);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment