快速写大文件 [英] writing large files quickly

查看:76
本文介绍了快速写大文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在做一些文件系统基准测试。在这个过程中,我需要

创建一个大文件来复制到各种驱动器。我正在创建这样的

文件:


fd = file(''large_file.bin'',''wb'')
x for xrange(409600000):
fd.write(''0'')
br />
这需要几分钟的时间。我怎样才能加快这个过程?


谢谢!

解决方案

提高速度的一种方法是写更大的字符串:


fd = file(''large_file.bin'',''wb'')
$ x $ b for x in xrange(51200000) :

fd.write(''00000000'')

fd.close()


然而,我打算在大约一个小时你会有更好的答案

或10. =)




rbt写道:

我一直在做一些文件系统基准测试。在这个过程中,我需要创建一个大文件来复制到各种驱动器。我正在创建这样的
文件:

fd = file(''large_file.bin'',''wb'')
for x in xrange(409600000) ):
fd.write(''0'')
fd.close()

这需要几分钟时间。我怎样才能加快这个过程?

谢谢!




未经测试,但这应该更快。


block =''0''* 409600

fd = file(''large_file.bin'',''wb'')

for x in范围(1000):

fd.write(''0'')

fd.close()


>未经测试,但这应该更快。


block =''0''* 409600
fd = file(''large_file.bin'',''wb'' )
for x in range(1000):
fd.write(''0'')
fd.close()




只是检查......你的意思是


fd.write(块)


对吗? :)否则,你的结果只有10000。

中的字符你的文件:)


有没有什么可以阻止一个人做以下事情?


fd .write(" 0" * 409600000)


这是一个非常短的时间内的一个巨大的字符串。它会跳过所有的b $ b循环,并允许Python将文件作为操作系统可以处理的速度快速地输出到磁盘上。 (和Python一样快,可以生成这个巨大的字符串)


-tkc

I''ve been doing some file system benchmarking. In the process, I need to
create a large file to copy around to various drives. I''m creating the
file like this:

fd = file(''large_file.bin'', ''wb'')
for x in xrange(409600000):
fd.write(''0'')
fd.close()

This takes a few minutes to do. How can I speed up the process?

Thanks!

解决方案

One way to speed this up is to write larger strings:

fd = file(''large_file.bin'', ''wb'')
for x in xrange(51200000):
fd.write(''00000000'')
fd.close()

However, I bet within an hour or so you will have a much better answer
or 10. =)



rbt wrote:

I''ve been doing some file system benchmarking. In the process, I need to
create a large file to copy around to various drives. I''m creating the
file like this:

fd = file(''large_file.bin'', ''wb'')
for x in xrange(409600000):
fd.write(''0'')
fd.close()

This takes a few minutes to do. How can I speed up the process?

Thanks!



Untested, but this should be faster.

block = ''0'' * 409600
fd = file(''large_file.bin'', ''wb'')
for x in range(1000):
fd.write(''0'')
fd.close()


> Untested, but this should be faster.


block = ''0'' * 409600
fd = file(''large_file.bin'', ''wb'')
for x in range(1000):
fd.write(''0'')
fd.close()



Just checking...you mean

fd.write(block)

right? :) Otherwise, you end up with just 1000 "0" characters in
your file :)

Is there anything preventing one from just doing the following?

fd.write("0" * 409600000)

It''s one huge string for a very short time. It skips all the
looping and allows Python to pump the file out to the disk as
fast as the OS can handle it. (and sorta as fast as Python can
generate this humongous string)

-tkc


这篇关于快速写大文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆