先定義兩個函數
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;