Java compares IO and NIO file read/write performance tests, ionio
Original article: test the file read/write performance of IO and NIO in java
Source code: http://www.zuidaima.com/share/1550463508466688.htm
1. NIO adopts a method closer to the operating system for IO execution: Channel and cache; as the name suggests, data from the data source is transmitted by the cache through the channel. 2. After JDK 5, NIO was used to optimize the underlying layer of the original IO system, which can be found in the source code published by sun. However, NIO is more systematic than IO. 3. I have studied the I/O source code and some sun source code. I think the performance bottleneck of the I/O system is mainly caused by the original I/O architecture. The original IO system uses the adapter mode, which seems to be a good idea at the beginning of JDK development. However, as the number of adapter nesting increases, IO usage is not only annoying, but also affects performance, because dynamic implementation must reduce performance. 4. In order to verify my ideas as accurately as possible, the code in the I/O section is also displayed and read and write with a buffer. 5. Local test: 50 m Files: 1031 ms for IO, 640 ms for NIO, 18900 ms for IO, and 13500 ms for NIO. Their time difference does not change dramatically due to changes in the file size, which means that the processing of data streams at the underlying layer, whether NIO or IO, should be similar, what causes IO performance constraints is the architecture of its original adapter model. Main Part of the Code: 1. IO system 2. NIO System