Why does having a Debug.log() make my script run twice as fast?

I have a script that runs A LOT slower when a debug line is removed. Consistently too. with debug line enabled, it runs at an average 4.5ms (230fps), but when I remove the debug line, it runs at 7.5-9ms (115-130fps) what the hell?

I’m using the FPSDisplay script from the wiki
http://wiki.unity3d.com/index.php?title=FramesPerSecond

You can try the following :

  • remove/disable the FPS script
  • open the Profiler, and under CPU, uncheck everything but Scripts
  • start playing, pause, scrub through the timeline
  • in the Profiler window, look for BehaviourUpdate, and find your script in it
  • then look for the number of milliseconds it used to process that frame
  • do the same with and without the Debug.Log

For reference, 60FPS = 16ms/per frame
You can’t rely on Framerate estimation. There’s usually a lot more going on in the background.