分别以1倍size,10倍size,100倍size写入同样大小的数据,分别测试大文件写入和内存拷贝。
tfwrite woaoniyoujifen,yueliangdaibiaowodexin!
small write 100w times begin ...
begin sec[1433735551], microsec[956743]
small write 100w time over.
end sec[1433735553], microsec[550436]
Large write 10w times begin ...
begin sec[1433735553], microsec[550470]
Large write 10w times end.
end sec[1433735553], microsec[719068]
SuperLarge write 1w times begin ...
begin sec[1433735553], microsec[719078]
SuperLarge write 1w times end.
end sec[1433735553], microsec[782787]
begin to 100w small strcpy
begin sec[1433735553], microsec[801839]
100w small strcpy over .
end sec[1433735553], microsec[879082]
begin to 10w large strcpy
begin sec[1433735553], microsec[885847]
10w Large strcpy over .
end sec[1433735553], microsec[930263]
begin to 1w Superlarge strcpy
begin sec[1433735553], microsec[936975]
1w SuperLarge strcpy over .
end sec[1433735553], microsec[978766]
从测试结果看出,在大文件写入上内存和硬盘的差距只有1倍。应该是硬盘和内存的IO效率差别并不是太大,文件写入和内存写入真正拉开的是随机小文件的读写上,硬盘需要寻道,内存地址直接访问。 至于1倍size的文件写入和10倍size文件写入有8倍差距,可能是和频繁的内核切换有关。