Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

BufferedInputStream vs BufferedReader  RSS feed

 
Rich Stepanski
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Other than bytes vs text... What is 'better'? Is a BufferedReader faster/more efficient than a BufferedInputStream?

If I was using a BufferedInputStream to read one line worth of bytes from a file, would that be slower than just using the readLine in the BufferedReader? Not clear on the benefit. Thanks.

(probably could of been put in Performance forum. Coin toss. Sorry)
 
Rich Stepanski
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
(I posted this earlier, but had to delete it and fix something. Now it's after the post that replies to it.)

Bytes vs. text is the only reason to care, I think. A BufferedInputStream is better for reading bytes; a BufferedReader is faster for reading characters or lines. Their speeds are probably comparable, but I can't really think of a context where it would make sense to compare them other than bytes vs. chars.
 
Rich Stepanski
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
(before reading, I assume PrintWriters are equivalent to BufferedOutputStreams also)

well, I just replaced BufferedInputStreams with BufferedReaders instead of my BufferedInputStreams. I'm reading and writing about a dozen 3 - 30 mb txt files. The Readers do seem to be faster?

I had this working before and the whole process took a few minutes. Now with the BufferedReaders it takes less than a minute? Now I did remove some manipulation things ( casting byte arrays to Strings ) and I added FileWriters in place of BufferedOutputStreams. Also, I have as many buffers as possible ( FileInputStream to BufferedInputStream to InputStreamReader to BufferedReader, same for output)

This is a rather drastic increase in performance. Am I right to assume its from the Readers/Writers? or just the removal of unneeded casting?

Either way, I'm running as fast as I needed.. haha, thanks.

[ October 23, 2004: Message edited by: rich Stepanski ]
[ October 23, 2004: Message edited by: rich Stepanski ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!