• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Application performance issue with System.out.println(); statement

 
jawaharlal vislawath
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Hi Friends,

Is System.out.println(); statement indeed hampers the performance of the application? Please give the valuable suggestions..

Thanks,
Jawahar
 
Winston Gutkowski
Bartender
Pie
Posts: 10422
63
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
jawaharlal vislawath wrote:Is System.out.println(); statement indeed hampers the performance of the application?

Not so much as you'd notice. And if you need it, what else would you do?

Winston
 
Mike Simmons
Ranch Hand
Posts: 3090
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It really depends - compared to what? What else does the application do? There are some applications where yes, System.out.println() will slow the application down considerably. There are many, many other applications where the effect is insignificant. The best way to find out for your application would be to simply measure the performance with the println() statements, then comment them out and measure again, without those same statements. But as Winston alludes - do you need them, or not?
 
fred rosenberger
lowercase baba
Bartender
Posts: 12143
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would think that EVERY line of code that gets executed impacts performance to some degree.
 
Jayesh A Lalwani
Rancher
Posts: 2756
32
Eclipse IDE Spring Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The System.out.println eventually gets translated to a write operation on some sort of buffer that drives the monitor. The write to the buffer should be very quick, but of course as others have said "COmpared to what". If you log a message every time you add 2 numbers, then you are going to spend more time in System.out . However, if you are logging a message everytime you run a complicated database query on 1 million rows, then the database query is going to take more time.

However, one thing you can be sure of is that system.out will cause contention. The buffer will be protected somehow from being accesses by multiple threads at the same time by a hardware/OS level lock (and might even be protected by multiple locks). So, if you have a large number of threads executing in parallel, they will lock each other up on the System.outs. Adding a lot of System.out is like adding a lot of synchronized blocks. Your multithreaded app is going to slow down because threads will be waiting on each other.
 
Luan Cestari
Ranch Hand
Posts: 167
C++ Redhat Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jayesh explained very nice. I would just recommend for general propose to use some Log framework which they are made to solve these problems (by the way, I think i saw a benchmark which shows that logback have the highest throughput ). If you are building/working on a system with tons of users, you probably would need some more elaborated solution.
 
jawaharlal vislawath
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you all for commenting on this post, Jayesh/Cestari indeed good view on alternate for this, as we need to use logger.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic