对于一个项目,我需要快速交换4字节的字。在使用其他计算算法之前,我需要切换大文件(2mb)的每个字(4字节)
def word_swaper(data):
buf_swaped_data = b""
number_of_words = int(len(data) / 4)
for word in range(number_of_words):
newword = data[word*4:(word+1)*4]
newword = newword[::-1]
buf_swaped_data += newword
有没有更快或更简单的方法?我将用它来处理大小约为2mb的文件,因此计算时间约为1-2分钟,这太长了
使用两个但是there's a built-in method for this这比我的机器快550倍io.BytesIO()
的基准测试在我的机器上的速度是3倍以上相关问题 更多 >
编程相关推荐