BufferedReader on top of BufferedInputStream VS BufferedReader on top of FileInputStream

63 Views Asked by At

Is there any performance gain if we have:

BufferedReader reader = new BufferedReader(new InputStreamReader(new BufferedInputStream(new FileInputStream("SOME_FILE")), StandardCharsets.UTF_8))

Notice that I added BufferedInputStream, which is unusual, to my experience.

Usually, it goes with out the added intermediate buffered input stream:

BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(""), StandardCharsets.UTF_8))

If there's a performance difference or not, how can I measure it?

What I tried is reading ~30 MB text file using both approaches, 3 times each.

To my surprise, without the buffered input stream was around 10% faster than its buffered correspondent.

I don't know if there are cases where the buffered version shine over the other or it's just a redundant buffering causing more overhead than it's useful.

0

There are 0 best solutions below