读书人

怎么提高这个程序的执行速度

发布时间: 2012-11-09 10:18:48 作者: rapoo

如何提高这个程序的执行速度?
程序的功能是读取硬盘上的3个文件,在申请的内存中让这3个文件异或,最后把目标文件写入磁盘。文件基本都是上百G的所以循环执行上面的操作。现在的问题是速度太慢,请帮忙看看怎么提高速度。部分源代码如下:

先申请内存
;**********************************************************************
;读指定文件到申请的虚拟内存
;**********************************************************************
push ecx ;压入的是要循环的次数,每次循环执行8M(1024*1024*8这个值是可以变化的)的异或操作,
invoke ReadFile,@hHD1,Buffer_Point1,BUFFER_SIZE,addr dwCount,NULL
.ifeax == 0
invoke MessageBox,0,$CTA0("读1.img文件错误"),NULL,MB_ICONEXCLAMATION
.endif
invoke ReadFile,@hHD2,Buffer_Point2,BUFFER_SIZE,addr dwCount,NULL
.ifeax == 0
invoke MessageBox,0,$CTA0("读4.img文件错误"),NULL,MB_ICONEXCLAMATION
.endif
invoke ReadFile,@hHD3,Buffer_Point3,BUFFER_SIZE,addr dwCount,NULL
.ifeax == 0
invoke MessageBox,0,$CTA0("读5.img文件错误"),NULL,MB_ICONEXCLAMATION
jmp_exit
.endif

jmp_PerXor
@@:
pushecx
invoke ReadFile,@hHD1,Buffer_Point1,BUFFER_SIZE,addr dwCount,NULL
invoke ReadFile,@hHD2,Buffer_Point2,BUFFER_SIZE,addr dwCount,NULL
invoke ReadFile,@hHD3,Buffer_Point3,BUFFER_SIZE,addr dwCount,NULL
;***************************************************************************
;执行异或操作
;***************************************************************************
_PerXor:
movecx,1024*1024*8/4 ;对应下面的loop指令中的ecx
movedi,Buffer_Point1 ;Buffer_Point1为指针变量,值为申请内存的地址,其他类似
movesi,Buffer_Point2
movebx,Buffer_Point3
@:
moveax,[edi]
xoreax,[esi]
xoreax,[ebx]
mov[edi],eax
addedi,4
addesi,4
addebx,4
loop@
;写入目标文件
invokeWriteFile,@hHD4,Buffer_Point1,BUFFER_SIZE,addr dwCount,NULL
.ifeax == 0
invokeMessageBox,0,$CTA0("写失败"),NULL,MB_OK
jmp_exit
.endif
popecx
dececx
cmpecx,0
jg@B

以下是我改写成读异步的源代码,在XP上执行正确但速度没什么提高,在windows2003的操作系统上面总是写失败,不知道什么原因。读异步一直没成功。请高手指教!invoke ReadFile,@hHD1,Buffer_Point1,BUFFER_SIZE,addr dwCount,NULL
.ifeax == 0
invoke MessageBox,0,$CTA0("读1.img文件错误"),NULL,MB_ICONEXCLAMATION
.endif
invoke ReadFile,@hHD2,Buffer_Point2,BUFFER_SIZE,addr dwCount,NULL
.ifeax == 0
invoke MessageBox,0,$CTA0("读4.img文件错误"),NULL,MB_ICONEXCLAMATION
.endif
invoke ReadFile,@hHD3,Buffer_Point3,BUFFER_SIZE,addr dwCount,NULL
.ifeax == 0
invoke MessageBox,0,$CTA0("读5.img文件错误"),NULL,MB_ICONEXCLAMATION
jmp_exit
.endif
mov@overlapped.loffset,0
mov@overlapped.OffsetHigh,0
cld
jmp_PerXor
@@:
pushecx
add@overlapped.loffset,BUFFER_SIZE
mov@overlapped.OffsetHigh,0
invoke ReadFile,@hHD1,Buffer_Point1,BUFFER_SIZE,addr dwCount,NULL
invoke ReadFile,@hHD2,Buffer_Point2,BUFFER_SIZE,addr dwCount,NULL
invoke ReadFile,@hHD3,Buffer_Point3,BUFFER_SIZE,addr dwCount,NULL
;***************************************************************************
;执行异或操作
;***************************************************************************
_PerXor:
movecx,1024*1024*64/4 ;对应下面的loop指令中的ecx
movedi,Buffer_Point1
movesi,Buffer_Point2
movebx,Buffer_Point3
@:
moveax,[edi]
xoreax,[esi]
xoreax,[ebx]
mov[edi],eax
addedi,4
addesi,4
addebx,4
loop@
;写入目标文件
invokeWriteFile,@hHD4,Buffer_Point1,BUFFER_SIZE,addr dwCount,addr @overlapped
.ifeax == 0
invokeMessageBox,0,$CTA0("写失败"),NULL,MB_OK
jmp_exit
.endif
popecx
dececx
cmpecx,0
jg@B

------解决方案--------------------


在一块硬盘上,每秒能写 40M 字节的目标文件就应该算很快了.

把三个文件放到三块不同的硬盘上,目标文件放到第四块硬盘上,应该能达到 80M ?

如果是四块固态盘,能达到 150M ?


另外 "内存映像文件只能小于2G吧",你理解的不对.但这不是关键.

关键是,对于数百G来说,硬盘太慢了.

读书人网 >汇编语言

热点推荐