Search code examples
c#optimizationoverheadoverhead-minimization

How important is it to use \n instead of using another print function


In C#, we have Console.WriteLine, and when programming a Linear Program, where optimization and overhead is important, I want to know, how necessary is it to use "\n" in the same Console.WriteLine instead of calling this again and again if I want to print lets say 10 lines:

Console.WriteLine("line1\n line2\n line3\n line4\n...");

as you can see this statement can be very long, and it's not a good programming habit.


Solution

  • The decision to split this into one or more lines of code is negligible compared to the time it actually takes to output anything to console. If you need performance, output less.