在中间层服务器,打包DataSet的资料,客户端用DataSet接收,有两种格式:
(1)、TDataSetProvider.Data得到的格式,姑且叫做Midas格式
(2)、ADO _Stream得到的格式,姑且叫做ADOStream格式,这其中又分为ADTG格式和XML格式。
下面测试ADO和Dbexpress两种数据库引擎,在生成不同的格式时的效率。
测试代码为:
function ADOReadData(ADataSet:TCustomADODataSet;AFormat:TPersistFormat=pfADTG):Variant;
var
vStream:_Stream;
vFilter:Variant;
begin
vStream:=CoStream.Create;
vFilter:=ADataSet.Recordset.Filter;
try
//先去掉Filter
ADataSet.Recordset.Filter:='';
if AFormat=pfADTG then
begin
vStream.type_:=adTypeBinary;
ADODB_TLB._Recordset(ADataSet.Recordset).Save(vStream,adPersistADTG);
vStream.Position:=0;
Result:=vStream.Read(vStream.Size);
end
else
begin
vStream.type_:=adTypeText;
OLEVariant(ADataSet.Recordset).Save(vStream,adPersistXML);
vStream.Position:=0;
Result:=vStream.ReadText(vStream.Size);
end;
finally
vStream:=nil;
ADataSet.Recordset.Filter:=vFilter;
end;
end;
procedure TForm4.Button1Click(Sender: TObject);
const
CNST_RepeatTimes=10;
var
i:integer;
A:TDateTime;
vData:Variant;
begin
//无图片
//SQLDataSet1.CommandText:='select * from csSystemLogs';
//ADODataSet1.CommandText:='select * from csSystemLogs';
//有图片
SQLDataSet1.CommandText:='select * from csMachines';
ADODataSet1.CommandText:='select * from csMachines';
A:=Now;
for i := 1 to CNST_RepeatTimes do
begin
SQLConnection1.Open;
SQLDataSet1.Open;
vData:=DataSetProvider1.Data;
SQLDataSet1.Close;
SQLConnection1.Close;
end;
Edit1.Text:=FloatToStr(Round((Now-A)*86400000));
Edit1_1.Text:=InttoStr(VarArrayHighBound(vData,1));
A:=Now;
for i := 1 to CNST_RepeatTimes do
begin
ADOConnection1.Open;
ADODataSet1.Open;
vData:=DataSetProvider2.Data;
ADODataSet1.Close;
ADOConnection1.Close;
end;
Edit2.Text:=FloatToStr(Round((Now-A)*86400000));
Edit2_1.Text:=InttoStr(VarArrayHighBound(vData,1));
A:=Now;
for i := 1 to CNST_RepeatTimes do
begin
ADOConnection1.Open;
ADODataSet1.Open;
vData:=ADOReadData(ADODataSet1,pfADTG);
ADODataSet1.Close;
ADOConnection1.Close;
end;
Edit3.Text:=FloatToStr(Round((Now-A)*86400000));
Edit3_1.Text:=InttoStr(VarArrayHighBound(vData,1));
A:=Now;
for i := 1 to CNST_RepeatTimes do
begin
ADOConnection1.Open;
ADODataSet1.Open;
vData:=ADOReadData(ADODataSet1,pfXML);
ADODataSet1.Close;
ADOConnection1.Close;
end;
Edit4.Text:=FloatToStr(Round((Now-A)*86400000));
Edit4_1.Text:=InttoStr(Length(WideString(vData))*2);
end;
测试结果:
1、资料表中有Image字段,连续打包10次。
序号 | Midas Dbexpress | Midas ADO | ADO Stream ADTG | ADO Stream XML |
打包时间(毫秒): | ||||
1 | 468 | 610 | 594 | 108672 |
2 | 484 | 469 | 578 | 108985 |
3 | 468 | 454 | 546 | 109023 |
4 | 484 | 454 | 562 | 109434 |
5 | 485 | 453 | 562 | 109828 |
返回资料大小(字节): | ||||
2603267 | 2603112 | 2603998 | 11186048 |
速度最快的是“Midas ADO”,资料最小的也是“Midas ADO”。“ADO Stream XML”效率差241倍,资料大小差4倍。
2、资料表中没有Image字段,连续打包10次。
序号 | Midas Dbexpress | Midas ADO | ADO Stream ADTG | ADO Stream XML |
打包时间(毫秒): | ||||
1 | 469 | 562 | 250 | 469 |
2 | 375 | 562 | 219 | 516 |
3 | 375 | 547 | 234 | 500 |
4 | 391 | 547 | 234 | 500 |
5 | 375 | 562 | 219 | 500 |
返回资料大小(字节): | ||||
177732 | 156805 | 182433 | 534026 |