Finding the optimal size for BufferedInputStream in Java

I have profiled my code loading a binary file. The boot time was approximately 15 seconds.

Most of the loading time came for methods that downloaded binary data.

I had the following code to create my DataInputStream:

is = new DataInputStream(
     new GZIPInputStream(
     new FileInputStream("file.bin")));

And I changed it to this:

is = new DataInputStream(
     new BufferedInputStream(
     new GZIPInputStream(
     new FileInputStream("file.bin"))));

So, after I made this small modification, the download code moved from 15 seconds to 4.

But then I discovered that BufferedInputStream has two constructors. Another constructor allows you to explicitly determine the size of the buffer.

I have two questions:

  • What size is selected in BufferedInputStream and is it perfect? If not, how can I find the optimal size for the buffer? Should I write a quick bit of code that performs a binary search?
  • BufferedInputStream? GZIPInputStream, . , - , , GZIP x ( x - ). GZIPInputStream? , .
+5
2

GZIPInputStream BufferedInputStream . BufferedInputStream GZIPInputStream . GZIPInputStream , , , .

BufferedInputStream - 8kb, , , . , , .

, . . GZIPInputStream ( 512 ), .

+8
  • . ( , ). , , , , .

  • :

    is = new DataInputStream(
         new BufferedInputStream(
         new GZIPInputStream(
         new FileInputStream("file.bin"))));
    

    BufferedInputStream GZIPInputStream, ( ).

    GZIPInputStream , , , , . , , gzip . , .

+4

All Articles