Fastest way to write an array of integers to a file in Java?

前端 未结 6 507
小鲜肉
小鲜肉 2020-12-05 08:33

As the title says, I\'m looking for the fastest possible way to write integer arrays to files. The arrays will vary in size, and will realistically contain anywhere between

6条回答
  •  没有蜡笔的小新
    2020-12-05 08:53

    The main improvement you can have for writing int[] is to either;

    • increase the buffer size. The size is right for most stream, but file access can be faster with a larger buffer. This could yield a 10-20% improvement.

    • Use NIO and a direct buffer. This allows you to write 32-bit values without converting to bytes. This may yield a 5% improvement.

    BTW: You should be able to write at least 10 million int values per second. With disk caching you increase this to 200 million per second.

提交回复
热议问题