Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
1
Question by ClearRoseOfWar · Jan 22, 2016 at 05:32 PM · programmingtimecompiler

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!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
4

Answer by Ville · Mar 22, 2017 at 09:16 AM

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: \n" + compileTime.ToString("0.000") + "s");
         }
     }
 }
Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image nicmarxp · Dec 27, 2017 at 08:35 PM 0
Share

This works great! For anyone confused like me on where to put it. If you put it in a folder called Scripts/Editor, it seems to run automatically. :) I would like to clear the console when it's run though. This can be done by adding the ClearConsole() method by ToBeGlad to this class and add it on line 34.

avatar image RunninglVlan · Nov 01, 2019 at 10:18 AM 0
Share

Stopped working in 2019.3 =( Wrote a post in forums about it

avatar image
2

Answer by Jessespike · Jan 22, 2016 at 08:03 PM

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: \n" + compileTime.ToString("0.000") + "s");
         }
     }
 
 }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

41 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

using several compilers, interpreter inside a game 0 Answers

Game Clock (Like in "The Escapist") 1 Answer

Trouble Navigating Pause Menu.... 0 Answers

enemy looking randomly? 0 Answers

Virtual Pet Game (Using the Bathroom) 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges