简体   繁体   中英

Unity when does Debug.Log write to console

I am trying to benchmark my algorithm. Sometimes it takes super long time and i would like to know where it has reached. But for some Reason Debug.log is not printing anything until the end of the update method.

I would like to see it to print text out step by step, but instead im getting all at once at the end of update cycle. Makediagram method is very slow. Depending on input can take 7-700 seconds.

private void Update()
{
if (i > 0) return;
int count = 16 * (int)Mathf.Pow(2, i);

    Debug.Log("New diagram");
        BowyerWatson bw = new BowyerWatson(BowyerWatson.STATE.STATE_3D, count, 0);
    Debug.Log("Points generated");
        float ctime = Time.realtimeSinceStartup;
        bw.MakeDiagram();
        time += Time.realtimeSinceStartup - ctime;
    Debug.Log("i:" + i + " j:" + j + " time:" + (Time.realtimeSinceStartup-ctime));


    j++;
    if(j == 20)
    {
        i++;
        j = 0;
        Debug.Log(count + " points took: " + time / 20 + "s on average");
        time = 0;
    }

}

Debug.Log writes immediately. The problem is that Update does not yield and wait for one task to end. What you really want here is a coroutine that yields while MakeDiagram() is running.

Or flag a boolean as true while MakeDiagram() is running and then in your Update() function, if the boolean is true, then return , and then flag the bool as false after MakeDiagram() has completed, to continue code execution.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM