首先说本机的性能,采用AS SSD Benchmark进行评测,写入能力大约在422M每秒,计划连续写入文本数据,直到达到要求为止(5G数据与10G数据),测试环境如下:
环境 | 版本 |
---|---|
JDK | 1.8.0_131 |
操作系统 | Windows 10 专业版 x64 |
CPU | Inter i7-3740QM |
内存 | 16G |
硬盘 | 三星512G SSD |
1. FileOutputStream与BufferedWriter
原以为FileOutputStream的性能会很低,BufferedWriter会有一定的性能提升,但结果却让我大吃一惊,测试数据如下:
测试编次 | 采用方式 | 文件大小 | 花费时间(秒) |
---|---|---|---|
1 | BufferedWriter | 4.5G | 10.678399057 |
2 | BufferedWriter | 4.5G | 10.808078377 |
3 | FileOutputStream | 4.5G | 9.755711962 |
4 | FileOutputStream | 4.5G |