Why is it that FileInputStream read is slower with bigger array

后端 未结 4 1588
盖世英雄少女心
盖世英雄少女心 2020-12-31 18:31

If I read bytes from a file into a byte[] I see that FileInputStream performance worse when the array is around 1 MB compared to 128 KB. On the 2 workstations I have tested

4条回答
  •  轮回少年
    2020-12-31 18:41

    Optimal buffer size depands on file system block size, CPU cache size and cache latency. Most os'es use block size 4096 or 8192 so it is recommended to use buffer with this size or multiplicity of this value.

提交回复
热议问题