1

I was wondering how much better for performance is using print("... \n ...") thanprintln("...") for printing multiple lines to the console for example with

"This is line one,

This is line two."

Method 1 is more readable however how much worse would it be for performance:

System.out.println("This is line one,");
System.out.println("This is line two.");

than Method 2:

System.out.print("This is line one, \n This is line two.");

Thanks in advance

e11i0t23
  • 141
  • 11
  • 1
    "how much worse would it be for performance" you'd have to measure it to get any meaningful answer. – Andy Turner Jun 09 '18 at 20:06
  • I was wondering if anyone had ever measured it before other wise i will – e11i0t23 Jun 09 '18 at 20:07
  • if you wrap a time around a loop that does each a million times, you can calculate the performance difference. However it may change between JVM versions and the platform you execute it on. – Dragonthoughts Jun 09 '18 at 20:07
  • `System.out` is generally on the slow side of things regardless. – Radiodef Jun 09 '18 at 20:12
  • If you use a buffered, non-autoflushing solution like in the dupe, you get better readability than Method 1 and better performance than Method 2. In that case, it probably doesn't matter how much slower one is than the other. – that other guy Jun 09 '18 at 20:51
  • The limiting factor is the console, not the code. – user207421 Jun 09 '18 at 22:02

0 Answers0