delphi 计算函数执行时间 TStopwatch
先定义两个函数
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;