auto commit
This commit is contained in:
197
Delphi/source/uTest.pas
Normal file
197
Delphi/source/uTest.pas
Normal file
@@ -0,0 +1,197 @@
|
||||
unit uTest;
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, System.DateUtils,
|
||||
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ComCtrls, Vcl.StdCtrls, Vcl.ExtCtrls, uIdGeneratorOptions, uIIdGenerator,
|
||||
uDefaultIdGenerator, uYitIdHelper;
|
||||
|
||||
type
|
||||
TfTest = class(TForm)
|
||||
mmo1: TMemo;
|
||||
Panel1: TPanel;
|
||||
Button1: TButton;
|
||||
btnTimeStamp: TButton;
|
||||
Button2: TButton;
|
||||
rgSelect: TRadioGroup;
|
||||
procedure Button1Click(Sender: TObject);
|
||||
procedure btnTimeStampClick(Sender: TObject);
|
||||
procedure Button2Click(Sender: TObject);
|
||||
procedure FormCreate(Sender: TObject);
|
||||
procedure FormClose(Sender: TObject; var Action: TCloseAction);
|
||||
private
|
||||
{ Private declarations }
|
||||
IdGeneratorOption: TIdGeneratorOptions;
|
||||
YitIdHelper: TYitIdHelper;
|
||||
public
|
||||
{ Public declarations }
|
||||
end;
|
||||
|
||||
var
|
||||
fTest: TfTest;
|
||||
|
||||
implementation
|
||||
|
||||
{$R *.dfm}
|
||||
|
||||
function GetMillisecondTimeStamp(): Int64;
|
||||
var
|
||||
ST: TDateTime;
|
||||
begin
|
||||
ST := EncodeDateTime(1970, 1, 1, 0, 0, 0, 0);
|
||||
Result := MilliSecondsBetween(Now(), ST) - 28800000; // 8*60*60*1000;
|
||||
end;
|
||||
|
||||
procedure TfTest.btnTimeStampClick(Sender: TObject);
|
||||
const
|
||||
T1 = 28800000;
|
||||
var
|
||||
SysTime: TSystemTime;
|
||||
Time1, Time2: TDateTime;
|
||||
T2, T3: Int64;
|
||||
begin
|
||||
// <20>뼶
|
||||
// mmo1.Lines.Add(IntToStr(DateTimeToUnix(EncodeDateTime(2020, 2, 20, 2, 20, 2, 20), False)));
|
||||
// mmo1.Lines.Add(IntToStr(DateTimeToUnix(EncodeDateTime(2020, 2, 20, 2, 20, 2, 20), True)));
|
||||
// mmo1.Lines.Add(FormatDateTime('yyyy-MM-dd HH:mm:ss.zzz',
|
||||
// UnixToDateTime(DateTimeToUnix(EncodeDateTime(2020, 2, 20, 2, 20, 2, 20), False), False)));
|
||||
mmo1.Lines.Add('<27><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>תΪUTCʱ<43>䣺' + IntToStr(DateTimeToUnix(Now(), False)));
|
||||
mmo1.Lines.Add('ֱ<><D6B1>ȡUTCʱ<43>䣺' + IntToStr(DateTimeToUnix(Now(), True)));
|
||||
// mmo1.Lines.Add(FormatDateTime('yyyy-MM-dd HH:mm:ss.zzz', UnixToDateTime(DateTimeToUnix(Now(), False), False)));
|
||||
// mmo1.Lines.Add(FormatDateTime('yyyy-MM-dd HH:mm:ss.zzz', UnixToDateTime(DateTimeToUnix(Now(), True), True)));
|
||||
|
||||
// <20><><EFBFBD>뼶
|
||||
Time2 := EncodeDateTime(1970, 1, 1, 0, 0, 0, 0);
|
||||
|
||||
// δ<><CEB4><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
||||
GetLocalTime(SysTime);
|
||||
Time1 := SystemTimeToDateTime(SysTime);
|
||||
T2 := MilliSecondsBetween(Time1, Time2);
|
||||
T3 := T2 - T1;
|
||||
mmo1.Lines.Add('LocalTime<6D><65>' + IntToStr(T3));
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
||||
GetSystemTime(SysTime);
|
||||
Time1 := SystemTimeToDateTime(SysTime);
|
||||
T2 := MilliSecondsBetween(Time1, Time2);
|
||||
T3 := T2 - T1;
|
||||
mmo1.Lines.Add('SystemTime<6D><65>' + IntToStr(T3));
|
||||
|
||||
// δ<><CEB4><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
||||
Time1 := Now();
|
||||
T2 := MilliSecondsBetween(Time1, Time2);
|
||||
T3 := T2 - T1;
|
||||
mmo1.Lines.Add('Now<6F><77>' + IntToStr(T3));
|
||||
end;
|
||||
|
||||
procedure TfTest.Button1Click(Sender: TObject);
|
||||
var
|
||||
options: TIdGeneratorOptions;
|
||||
IdGen: IIdGenerator;
|
||||
i, j: Integer;
|
||||
begin
|
||||
// ʹ<>÷<EFBFBD>ʽһ<CABD><D2BB>ֱ<EFBFBD><D6B1>ʹ<EFBFBD><CAB9>
|
||||
options := TIdGeneratorOptions.Create;
|
||||
try
|
||||
with options do
|
||||
begin
|
||||
Method := rgSelect.ItemIndex + 1;
|
||||
// BaseTime := DateTime.Now.AddYears(-10);
|
||||
WorkerId := 2;
|
||||
|
||||
WorkerIdBitLength := 6;
|
||||
SeqBitLength := 6;
|
||||
|
||||
MaxSeqNumber := 0;
|
||||
MinSeqNumber := 5;
|
||||
|
||||
TopOverCostCount := 2000;
|
||||
|
||||
DataCenterId := 0;
|
||||
DataCenterIdBitLength := 0;
|
||||
|
||||
TimestampType := 0;
|
||||
end;
|
||||
|
||||
IdGen := TDefaultIdGenerator.Create(options);
|
||||
|
||||
j := 100;
|
||||
Screen.Cursor := crHourGlass;
|
||||
mmo1.Lines.BeginUpdate();
|
||||
try
|
||||
for i := 1 to j do
|
||||
begin
|
||||
mmo1.Lines.Add(FormatFloat('000', i) + '<27><>' + IntToStr(IdGen.NewLong()));
|
||||
end;
|
||||
mmo1.Perform(WM_VSCROLL, SB_BOTTOM, 0)
|
||||
finally
|
||||
mmo1.Lines.EndUpdate();
|
||||
Screen.Cursor := crDefault;
|
||||
end;
|
||||
|
||||
finally
|
||||
options.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TfTest.Button2Click(Sender: TObject);
|
||||
const
|
||||
Total = 5000000;
|
||||
var
|
||||
i: Integer;
|
||||
Id: Int64;
|
||||
ST, ET, Elapse: Cardinal;
|
||||
begin
|
||||
Screen.Cursor := crHourGlass;
|
||||
try
|
||||
ST := GetTickCount();
|
||||
for i := 1 to Total do
|
||||
begin
|
||||
Id := YitIdHelper.NextId();
|
||||
end;
|
||||
ET := GetTickCount();
|
||||
finally
|
||||
Screen.Cursor := crDefault;
|
||||
end;
|
||||
Elapse := ET - ST;
|
||||
mmo1.Lines.Add(Format('<27><><EFBFBD><EFBFBD>500<30><30><EFBFBD><EFBFBD>ʱ<EFBFBD>䣺%d<><64><EFBFBD>룬ƽ<EBA3AC><C6BD>ÿ<EFBFBD><C3BF>%d<><64><EFBFBD><EFBFBD>', [Elapse, Trunc((Total / Elapse) * 1000)]));
|
||||
|
||||
end;
|
||||
|
||||
procedure TfTest.FormClose(Sender: TObject; var Action: TCloseAction);
|
||||
begin
|
||||
YitIdHelper.Free;
|
||||
IdGeneratorOption.Free;
|
||||
end;
|
||||
|
||||
procedure TfTest.FormCreate(Sender: TObject);
|
||||
begin
|
||||
IdGeneratorOption := TIdGeneratorOptions.Create;
|
||||
// Ĭ<>ϲ<EFBFBD><CFB2><EFBFBD>
|
||||
with IdGeneratorOption do
|
||||
begin
|
||||
Method := rgSelect.ItemIndex + 1;
|
||||
// BaseTime := DateTime.Now.AddYears(-10);
|
||||
WorkerId := 2;
|
||||
|
||||
WorkerIdBitLength := 6;
|
||||
SeqBitLength := 6;
|
||||
|
||||
MaxSeqNumber := 0;
|
||||
MinSeqNumber := 5;
|
||||
|
||||
TopOverCostCount := 2000;
|
||||
|
||||
DataCenterId := 0;
|
||||
DataCenterIdBitLength := 0;
|
||||
|
||||
TimestampType := 0;
|
||||
end;
|
||||
|
||||
// ʹ<>÷<EFBFBD>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>װ<EFBFBD><D7B0>ʹ<EFBFBD><CAB9>
|
||||
YitIdHelper := TYitIdHelper.Create;
|
||||
YitIdHelper.SetIdGenerator(IdGeneratorOption);
|
||||
end;
|
||||
|
||||
end.
|
||||
Reference in New Issue
Block a user