⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 inliningform.pas

📁 source code for Marco Cantu s book Delphi 2007 Handbook
💻 PAS
字号:
unit InliningForm;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  /// form principale
  TForm3 = class(TForm)
    bntLenght: TButton;
    btnLengthInline: TButton;
    btnMaxInline: TButton;
    Memo1: TMemo;
    btnMax: TButton;
    /// calcola il massimo
    procedure btnMaxClick(Sender: TObject);
    procedure btnMaxInlineClick(Sender: TObject);
    procedure btnLengthInlineClick(Sender: TObject);
    procedure bntLenghtClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  /// ecco la form
  Form3: TForm3;

implementation

{$R *.dfm}

uses
  timetest_clock, Math;

const
  LoopCount = 100000000;
var
  ssample : string;

{$INLINE ON}

function LengthStdcall (const s: AnsiString): Longint;
begin
  Result := Integer(S);
  if Result <> 0 then
    Result := PInteger(Result-4)^;
end;

procedure TForm3.bntLenghtClick(Sender: TObject);
var
  ttt: TTimeTest;
  I, J: Integer;
begin
  ssample:= 'sample string';
  J := 0;
  ttt := TTimeTest.Create;
  try
    for I := 0 to LoopCount do
      Inc (J, LengthStdcall (ssample));
    memo1.Lines.Add ('Length ' + ttt.Elapsed + '[' + IntToStr (J) + ']');
  finally
    FreeAndNil (ttt);
  end;
end;

procedure TForm3.btnLengthInlineClick(Sender: TObject);
var
  ttt: TTimeTest;
  I, J: Integer;
begin
  ssample:= 'sample string';
  J := 0;
  ttt := TTimeTest.Create;
  try
    for I := 0 to LoopCount do
      Inc (J, Length (ssample));
    memo1.Lines.Add ('Inline ' + ttt.Elapsed + '[' + IntToStr (J) + ']');
  finally
    FreeAndNil (ttt);
  end;
end;

procedure TForm3.btnMaxInlineClick(Sender: TObject);
var
  ttt: TTimeTest;
  I, J: Integer;
begin
  J := 0;
  ttt := TTimeTest.Create;
  try
    for I := 0 to LoopCount do
      J := Max (I, J);
    memo1.Lines.Add ('Max ' + ttt.Elapsed + '[' + IntToStr (J) + ']');
  finally
    FreeAndNil (ttt);
  end;
end;

{$INLINE OFF}
procedure TForm3.btnMaxClick(Sender: TObject);
var
  ttt: TTimeTest;
  I, J: Integer;
begin
  J := 0;
  ttt := TTimeTest.Create;
  try
    for I := 0 to LoopCount do
      J := Max (I, J);
    memo1.Lines.Add ('Off ' + ttt.Elapsed + '[' + IntToStr (J) + ']');
  finally
    FreeAndNil (ttt);
  end;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -