1 使用file reader测试随机io时间。
实验非预期结果:
a 当我修改了small.txt文件内容时,下一个循环依然是旧的内容,new,read操作读的是缓存??
b 当只执行一次read操作时,执行时间不足1ms,比想象中的快。据说磁盘寻道时间需要几毫秒??
@Test public void testSeek() throws IOException { int num = 100; char[] cbuf = new char[12 * 10]; long start = System.currentTimeMillis(); for (int i = 0; i < num; i++) { FileReader fr = new FileReader("small.txt"); // System.out.println(System.currentTimeMillis() - start); fr.read(cbuf); fr.close(); System.out.println(new String(cbuf).toString()); } System.out.println(System.currentTimeMillis() - start); }
有人能回答我的问题吗
哆啦的时光机
相关分类