csvdocument: added performance test mode to test suite

csvdocument: changed test suite project settings to generate asm listing


git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@1477 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
vvzh
2011-01-31 17:43:45 +00:00
parent 5fcdc6d075
commit d4da5d7108
2 changed files with 90 additions and 25 deletions

View File

@ -40,7 +40,7 @@
</Units> </Units>
</ProjectOptions> </ProjectOptions>
<CompilerOptions> <CompilerOptions>
<Version Value="9"/> <Version Value="10"/>
<Target> <Target>
<Filename Value="testcsvdoc"/> <Filename Value="testcsvdoc"/>
</Target> </Target>
@ -61,6 +61,9 @@
<OverflowChecks Value="True"/> <OverflowChecks Value="True"/>
<StackChecks Value="True"/> <StackChecks Value="True"/>
</Checks> </Checks>
<Optimizations>
<OptimizationLevel Value="2"/>
</Optimizations>
</CodeGeneration> </CodeGeneration>
<Linking> <Linking>
<Debugging> <Debugging>
@ -71,6 +74,7 @@
<CompilerMessages> <CompilerMessages>
<UseMsgFile Value="True"/> <UseMsgFile Value="True"/>
</CompilerMessages> </CompilerMessages>
<CustomOptions Value="-al"/>
<CompilerPath Value="$(CompPath)"/> <CompilerPath Value="$(CompPath)"/>
</Other> </Other>
</CompilerOptions> </CompilerOptions>

View File

@ -38,31 +38,40 @@ begin
FindClose(SearchRec); FindClose(SearchRec);
end; end;
procedure TestCsvFile(const AFilename: String; ADocument: TCSVDocument); function TestCsvString(ADocument: TCSVDocument; const AnInput: String;
out AParseTime, ABuildTime: Int64): String;
var
Start: TDateTime;
begin
ADocument.Clear;
Start := Now;
ADocument.CSVText := AnInput;
AParseTime := MilliSecondsBetween(Start, Now);
Start := Now;
Result := ADocument.CSVText;
ABuildTime := MilliSecondsBetween(Start, Now);
end;
procedure TestCsvFile(ADocument: TCSVDocument; const AnInputFilename,
ASampleOutputFilename: String);
var var
InBuffer, OutBuffer: String; InBuffer, OutBuffer: String;
SampleBuffer: String; SampleBuffer: String;
CsvDoc: TCSVDocument; ParseTime: Int64;
Start: TDateTime; BuildTime: Int64;
MSec: Int64;
begin begin
InBuffer := ReadStringFromFile(AFilename); InBuffer := ReadStringFromFile(AnInputFilename);
SampleBuffer := ReadStringFromFile(ChangeFileExt(AFilename, SampleBuffer := ReadStringFromFile(ASampleOutputFilename);
'.sample' + ExtractFileExt(AFilename)));
if SampleBuffer = '' then if SampleBuffer = '' then
SampleBuffer := InBuffer; SampleBuffer := InBuffer;
ADocument.CSVText := ''; OutBuffer := TestCsvString(ADocument, InBuffer, ParseTime, BuildTime);
Start := Now;
ADocument.CSVText := InBuffer;
MSec := MilliSecondsBetween(Start, Now);
OutBuffer := ADocument.CSVText;
Write(ExtractFileName(AFilename)); Write(ExtractFileName(AnInputFilename));
if OutBuffer = InBuffer then if OutBuffer = InBuffer then
begin begin
Write(': ok'); Write(': ok');
WriteLn(' (parsed in ', MSec, ' ms)'); WriteLn(' (parsed in ', BuildTime, ' ms)');
end else end else
begin begin
WriteLn(': FAILED'); WriteLn(': FAILED');
@ -74,20 +83,60 @@ begin
end; end;
end; end;
procedure PerformTests(ADocument: TCSVDocument; const ASpec: String); procedure ExecTests(ADocument: TCSVDocument; const ASpec: String);
var var
I: Integer; I: Integer;
TestFiles: TStringList; TestFiles: TStringList;
CurrentTestFile: String;
InBuffer, OutBuffer: String;
begin begin
WriteLn('== Format: ', ASpec, ' =='); WriteLn('== Format: ', ASpec, ' ==');
TestFiles := TStringList.Create; TestFiles := TStringList.Create;
FindTestFiles(TestFiles, ASpec); FindTestFiles(TestFiles, ASpec);
for I := 0 to TestFiles.Count - 1 do for I := 0 to TestFiles.Count - 1 do
TestCsvFile(TestFiles[I], ADocument); begin
CurrentTestFile := TestFiles[I];
TestCsvFile(ADocument,
CurrentTestFile,
ChangeFileExt(CurrentTestFile, '.sample' + ExtractFileExt(CurrentTestFile)));
end;
FreeAndNil(TestFiles); FreeAndNil(TestFiles);
WriteLn(); WriteLn();
end; end;
procedure ExecPerformanceTest(ADocument: TCSVDocument; const AMinSizeKB: Integer);
const
CsvLineEnding = #13#10;
var
I, MaxRows: Integer;
Seq: String;
SeqLen: Integer;
RealSize: Integer;
InBuffer, OutBuffer: String;
ParseTime: Int64;
BuildTime: Int64;
begin
WriteLn('== Performance test: ==');
WriteLn('Preparing the test...');
Seq := '"abcd efg";"hij""k;l;m;n";opqrstuvw; xyz12 ;"3456'#13#10'7890'#13#10;
SeqLen := Length(Seq);
MaxRows := ((AMinSizeKB * 1024) div SeqLen) + 1;
InBuffer := '';
RealSize := 0;
for I := 0 to MaxRows do
begin
InBuffer := InBuffer + Seq;
Inc(RealSize, SeqLen);
end;
WriteLn('Testing with ', RealSize div 1024, ' KB of CSV data...');
TestCsvString(ADocument, InBuffer, ParseTime, BuildTime);
WriteLn('Parsed in ', ParseTime, ' ms');
WriteLn('Built in ', BuildTime, ' ms');
end;
var var
CsvDoc: TCSVDocument; CsvDoc: TCSVDocument;
begin begin
@ -95,17 +144,29 @@ begin
WriteLn('-------------------'); WriteLn('-------------------');
CsvDoc := TCSVDocument.Create; CsvDoc := TCSVDocument.Create;
if ParamStr(1) = 'p' then
begin
CsvDoc.Delimiter := ';';
CsvDoc.QuoteChar := '"';
CsvDoc.LineEnding := #13#10;
CsvDoc.EqualColCountPerRow := False;
CsvDoc.IgnoreOuterWhitespace := False;
CsvDoc.QuoteOuterWhitespace := True;
ExecPerformanceTest(CsvDoc, StrToIntDef(ParamStr(2), 1));
end else
begin
// no setup needed, rfc4180 supported out-of-the-box // no setup needed, rfc4180 supported out-of-the-box
PerformTests(CsvDoc, 'rfc4180'); ExecTests(CsvDoc, 'rfc4180');
// setup for unofficial Creativyst spec // setup for unofficial Creativyst spec
PerformTests(CsvDoc, 'unofficial'); ExecTests(CsvDoc, 'unofficial');
// setup for MS Excel files // setup for MS Excel files
PerformTests(CsvDoc, 'msexcel'); ExecTests(CsvDoc, 'msexcel');
// setup for OOo Calc files // setup for OOo Calc files
PerformTests(CsvDoc, 'oocalc'); ExecTests(CsvDoc, 'oocalc');
end;
FreeAndNil(CsvDoc); FreeAndNil(CsvDoc);
WriteLn('------------------'); WriteLn('------------------');