我 这边 不是
..........................
fast 0.05 秒
normal 0.27 秒
slow 1.99 秒
..........................
fast 0.05 秒
normal 0.25 秒
slow 1.91 秒
..........................
fast 0.04 秒
normal 0.25 秒
slow 1.94 秒
..........................
fast 0.05 秒
normal 0.25 秒
slow 1.90 秒
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, math, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
i, b: integer;
function fast(n: integer): Extended;
var
i: DWORD;
begin
i := 31 - n;
result := (INFINITE shr i shl i) / $80000000;
end;
function normal(n: integer): Extended;
begin
result := 2 - (1 / Power(2, n));
end;
function slow(n: integer): Extended;
var
i: integer;
begin
result := 1;
for i := 1 to ndo
result := result + 1 / Power(2, i);
end;
begin
// showmessage(format('%1.9f %1.9f %1.9f', [fast(8), normal(8), slow(8)]));
memo1.Lines.Add('..........................') ;
b := GetTickCount;
for i := 1 to 1000000do
fast(8);
memo1.Lines.Add (format('fast %f 秒', [(GetTickCount - b) / 1000]));
b := GetTickCount;
for i := 1 to 1000000do
normal(8);
memo1.Lines.Add(format('normal %f 秒', [(GetTickCount - b) / 1000]));
b := GetTickCount;
for i := 1 to 1000000do
slow(8);
memo1.Lines.Add(format('slow %f 秒', [(GetTickCount - b) / 1000]));
end;
end.