How to measure the amount of time it takes for unity to compile (To compensate Mathematically)

I am trying to figure out how to get the amount of time unity has taken to recompile scripts

Heres what I am trying:

float compiletime = (float)EditorApplication.timeSinceStartup; 
Debug.Log (compiletime);
while(EditorApplication.isCompiling){  
	Debug.Log("Unity is Compiling");
}
compiletime = compiletime - (float)EditorApplication.timeSinceStartup;
Debug.Log (-compiletime);

Any help is appreciated!

I made a version based on InitializeOnLoad and PlayerPrefs, no need to start up an editor window.

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: 

" + compileTime.ToString(“0.000”) + “s”);
}
}
}

This is a neat idea and I gave it a shot. I tried to make the class run when the Editor starts with InitializeOnLoad, but the class and the variables would reset during script re-compilation. I thought about using PlayerPrefs to store the time variable, but instead I just made it an EditorWindow, not ideal, but it’s something to start testing.

using UnityEditor;
using UnityEngine;

class CompileTime : EditorWindow
{
	bool isTrackingTime;
	double startTime, finishTime, compileTime;

	[MenuItem("Window/Compile Time")]
	public static void Init()
	{
		EditorWindow.GetWindow(typeof(CompileTime));
	}

	void Update()
	{
		if (EditorApplication.isCompiling && !isTrackingTime)
		{
			startTime = EditorApplication.timeSinceStartup; 
			isTrackingTime = true;
		}
		else if (!EditorApplication.isCompiling && isTrackingTime)
		{
			finishTime = EditorApplication.timeSinceStartup; 
			isTrackingTime = false;

			compileTime = finishTime - startTime;

			Debug.Log("Script compilation time: 

" + compileTime.ToString(“0.000”) + “s”);
}
}

}