I'm loading a 2D array from file, it's 15,000,000 * 3 ints big (it will be 40,000,000 * 3 eventually). Right now, I use dataInputStream.readInt() to sequentially read the ints. It takes ~15 seconds. Can I make it significantly (at least 3x) faster or is this about as fast as I can get?
Yes, you can. From benchmark of 13 different ways of reading files:
If you have to pick the fastest approach, it would be one of these:
FileChannel with a MappedByteBuffer and array reads.FileChannel with a direct ByteBuffer and array reads.FileChannel with a wrapped array ByteBuffer and direct array access.For the best Java read performance, there are 4 things to remember:
BufferedInputStream).FileChannel and MappedByteBuffer.FileChannel with memory mapping, or a direct
or wrapped array ByteBuffer.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With