不同缓冲区读写文件的效率比较
环境:CentOS6.3/ext3/
读取文件大小:100000000B
BUFSIZE
|
TIMECOST
|
1
|
real 0m38.909s user 0m5.960s sys 0m32.888s |
2 | real 0m20.015s user 0m2.927s sys 0m17.063s |
4
|
real 0m11.065s
user 0m1.551s
sys 0m9.491s
|
8
|
real 0m5.160s
user 0m0.766s
sys 0m4.390s
|
16
|
real 0m2.670s
user 0m0.360s
sys 0m2.310s
|
32
|
real 0m1.306s
user 0m0.181s
sys 0m1.124s
|
64
|
real 0m0.656s
user 0m0.094s
sys 0m0.561s
|
128
|
real 0m0.367s
user 0m0.042s
sys 0m0.325s
|
256
|
real 0m0.180s
user 0m0.026s
sys 0m0.153s
|
512
|
real 0m0.093s
user 0m0.013s
sys 0m0.081s
|
1024
|
real 0m0.056s
user 0m0.006s
sys 0m0.049s
|
2048
|
real 0m0.035s
user 0m0.002s
sys 0m0.033s
|
4096
|
real 0m0.025s
user 0m0.001s
sys 0m0.023s
|
8192
|
real 0m0.022s
user 0m0.002s
sys 0m0.019s
|
16384
|
real 0m0.020s
user 0m0.003s
sys 0m0.016s
|
python读写效率比较
实现方式 |
timecost
|
raw_input
|
real 0m0.493s
user 0m0.420s
sys 0m0.066s
|
sys.stdin.read() |
real 0m0.102s
user 0m0.013s
sys 0m0.089s
|
sys.stdin.readlines()
|
real 0m0.258s
user 0m0.088s
sys 0m0.148s
|