先定义两个函数

    function sumX(x, y: Integer): Integer;
    function sumY(x, y: Integer): Integer; inline;

计算函数执行时间

procedure TForm5.Button5Click(Sender: TObject);
var
  sw: TStopwatch;
  i, j: Integer;
begin
  j := 0;
  sw := TStopwatch.StartNew;
  for i := 0 to 100000000 do
  begin
    j := sumX(i, j); //普通函数 
  end;
  sw.Stop;
  ShowMessage('first do expand time =' + IntToStr(sw.ElapsedMilliseconds) + ' '); //602

  j := 0;
  sw := TStopwatch.StartNew;
  for i := 0 to 100000000 do
  begin
    j := sumY(i, j);   //inline函数
  end;
  sw.Stop;
  ShowMessage('second do expand time =' + IntToStr(sw.ElapsedMilliseconds) + ' '); //595

end;

 

相关文章:

  • 2021-09-17
  • 1970-01-01
  • 2021-12-15
  • 2022-12-23
  • 2021-11-04
  • 2021-12-27
  • 2021-07-11
猜你喜欢
  • 2021-12-24
  • 2021-12-18
  • 2021-12-24
  • 2022-12-23
  • 2022-12-23
  • 2021-12-15
相关资源
相似解决方案