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:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 | |
} | |
} |
References
– https://docs.unity3d.com/Manual/Console.html
Related Posts
1 Comment + Add Comment
Leave a comment
Recent posts
- UnityHub: Enable built-in Login Dialog (no more browser login/logout issues!)
- Use TikTok-TTS in Unity (with WebRequest)
- Create Scene Thumbnail Image using OnSceneSaved & OnPreviewGUI
- webgl+javascript TTS
- Using Moonsharp (LUA) + Unity Webgl
- Using 3D gameobject prefabs with Unity Tilemap + NavMesh Surface
- Custom Unity Hub Project Template Preview Image/Video (using HTML+CSS in package description)
- Check if point is inside polygon 2D (using line intersection)
- UnityHub: Enable Create Project Button (without having to select Cloud Organization)
- UI: Make Tooltip background fit Text content length
- Pong-Wars in Unity
- Install Android SDK+JDK+NDK for Unity (without AndroidStudio or Unity Hub)
good one also, switch to single line log messages:
https://twitter.com/FreyaHolmer/status/1039497474384244739