Topic: Compare Time Use Append And Insert
I Try Create Log
have Row More Than 10,000,000 Record On TableGrid per Day
IF record + 1 >>>> 10,000,001
1. Append data Last Row Only
Compare
2. Insert data First Row Only
It takes more time to run ???
1. Append data Last Row Only
Form1.tb_api_log.AddRow(1);
Form1.tb_api_log.Cells[ 0,Form1.tb_api_log.RowCount ]:= NOW() ;
2. Insert data First Row Only
Form1.tb_api_log.InsertRow(0,1);
Form1.tb_api_log.Cells[0,0]:= NOW() ;
Example Code
procedure Form1_Button3_OnClick (Sender: TObject; var Cancel: boolean);
var
max_row : Integer ;
time_start, time_end: Cardinal;
time_use: Double;
begin
max_row := Form1.TableGrid1.RowCount ;
time_start := GetTickCount;
Form1.TableGrid1.InsertRow(0,1);
Form1.TableGrid1.ScrollToRow(0) ;
Form1.TableGrid1.Cells[0,0] := IntToStr(max_row+1 ) ;
Form1.TableGrid1.Cells[1,0] := FormatDateTime('yyyy-mm-dd hh:mm:ss.zzz', NOW);
Form1.TableGrid1.Cells[2,0] := IntToHex(max_row+1,8) ;
Form1.TableGrid1.Cells[3,0] := StrToMD5(IntToHex(max_row+1,8));
time_end := GetTickCount;
time_use := time_end - time_start;
Form1.TableGrid1.Cells[4,0] := FloatToStr(time_use) ;
Application.ProcessMessages ;
end;
procedure Form1_Button2_OnClick (Sender: TObject; var Cancel: boolean);
var
max_row : Integer ;
time_start, time_end: Cardinal;
time_use: Double;
begin
time_start := GetTickCount;
max_row := Form1.TableGrid1.RowCount ;
Form1.TableGrid1.AddRow(1);
Form1.TableGrid1.ScrollToRow(max_row) ;
Form1.TableGrid1.Cells[0,max_row] := IntToStr(max_row+1 ) ;
Form1.TableGrid1.Cells[1,max_row] := FormatDateTime('yyyy-mm-dd hh:mm:ss.zzz', NOW);
Form1.TableGrid1.Cells[2,max_row] := IntToHex(max_row+1,8) ;
Form1.TableGrid1.Cells[3,max_row] := StrToMD5(IntToHex(max_row+1,8));
time_end := GetTickCount;
time_use := time_end - time_start;
Form1.TableGrid1.Cells[4,max_row] := FloatToStr(time_use) ;
Application.ProcessMessages ;
end;
procedure Form1_Button1_OnClick (Sender: TObject; var Cancel: boolean);
Var
i : Integer ;
time_start, time_end: Cardinal;
time_use: Double;
begin
Form1.TableGrid1.dbSQL := 'SELECT "" AS Event,"" as DateTime,"" as Character,"" as MD,"" Duration';
Form1.TableGrid1.dbSQLExecute ;
Form1.TableGrid1.ClearRows ;
For i := 0 To 9999 Do
Begin
Form1.TableGrid1.ScrollToRow(i) ;
time_start := GetTickCount;
Form1.TableGrid1.InsertRow(0,1);
Form1.TableGrid1.Cells[0,0] := IntToStr(i+1) ;
Form1.TableGrid1.Cells[1,0] := FormatDateTime('yyyy-mm-dd hh:mm:ss.zzz', NOW);
Form1.TableGrid1.Cells[2,0] := IntToHex(i+1,8) ;
Form1.TableGrid1.Cells[3,0] := StrToMD5(IntToHex(i+1,8));
time_end := GetTickCount;
time_use := time_end - time_start;
Form1.TableGrid1.Cells[4,0] := FloatToStr(time_use) ;
Application.ProcessMessages ;
End;
end;
begin
end.
Easy For Beginner Student For Me