zoukankan      html  css  js  c++  java
  • 初学 Delphi 嵌入汇编[28] 把 EAX 的值置为 0 的三种方法与效率

    //以下三个函数功能一样, 但效率不同
    
    {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;
    
  • 相关阅读:
    otto-group-product-classification-challenge(Pytorch处理多分类问题)
    F1值
    win10 安装torch
    win10 安装 scrapy
    头条 街拍
    1029 Median
    欧拉回路
    Pre-Post
    Django 安装for Python3.4
    Python 安装for Windows
  • 原文地址:https://www.cnblogs.com/del/p/1058443.html
Copyright © 2011-2022 走看看