匯編語言測試:到底是加快還是乘快?
在windows中測試機器語言中關於加快還是乘快的問題,這裏隻是用到了低精度的計時器GetTickCount,測試機器為:
內存:512MB
cpu: AMD Sempron 2400+ 單核2GHz
測試代碼如下:
buf dword 256 dup(?) AddWay proc TIMES = 10000000h AddWay proc mov ecx,TIMES xor eax,eax .while ecx .if eax == 256 xor eax,eax .endif mov buf[eax],0aabbccddh add eax,4 dec ecx .endw ret AddWay endp MulWay proc mov ecx,TIMES xor eax,eax .while ecx .if eax == 256 xor eax,eax .endif mov buf[eax * 4],0aabbccddh dec ecx .endw ret MulWay endp
測試結果為(平均):
AddWay 720
MulWay 810
最後更新:2017-04-03 05:38:54