Aug
7
2018

Faster Debug.Log

Debug.Log() slows down your editor or even hangs if it happens to run inside some long loop,
but you can make it faster by disabling stacktrace from Debug.Log()! (see image above)

Tested for-loop with 100000 iterations in editor (Unity 2018.1.6f1)
– 25000ms with stacktrace enabled
– 2200ms with stacktrace disabled


code used for measuring:


// measure debug.log with large loop
using UnityEngine;
public class LogSpamTest : MonoBehaviour
{
void Start()
{
var stopwatch = new System.Diagnostics.Stopwatch();
stopwatch.Start();
for (int i = 0; i < 100000; i++)
{
Debug.Log(i);
}
stopwatch.Stop();
Debug.Log("Timer: " + stopwatch.ElapsedMilliseconds);
stopwatch.Reset();
// with stacktrace = 25000 ms
// without stacktrace = 2200 ms
}
}

view raw

LogSpamTest.cs

hosted with ❤ by GitHub


References

https://docs.unity3d.com/Manual/Console.html


1 Comment + Add Comment

Leave a comment

Connect

Twitter View LinkedIn profile Youtube Github Join Discord Twitch Instagram BlueSky

UnityLauncherPro

Get UnityLauncherPRO and work faster with Unity Projects!
*free unity hub alternative

@unitycoder_com

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.