初学Delphi嵌入汇编[28] - 把EAX的值置为0的三种方法与效率2012-04-16 博客园 万一//以下三个函数功能一样, 但效率不同{Fun1 需要读取常数 0, 最慢} function Fun1: Integer; asm mov eax, 0 end;{Fun2 与 Fun3 只是操作 CPU 的寄存器, 比 Fun1 快}function Fun2: Integer; asm sub eax, eax end; {Fun3 最快} function Fun3: Integer; asm xor eax, eax end;//速度测试procedure TForm1.Button1Click(Sender: TObject); var t: Cardinal; i: Integer; begin t := GetTickCount; for i := 0 to 100000000 do Fun1; t := GetTickCount - t; ShowMessage(IntToStr(t)); {均: 600 多} t := GetTickCount; for i := 0 to 100000000 do Fun2; t := GetTickCount - t; ShowMessage(IntToStr(t)); {均: 500 多} t := GetTickCount; for i := 0 to 100000000 do Fun3; t := GetTickCount - t; ShowMessage(IntToStr(t)); {均: 400 多} end;