[fpc-pascal] [Lazarus] Tests results of several pascal based JSON parsers
Michael Van Canneyt
michael at freepascal.org
Fri Aug 30 17:47:29 CEST 2019
On Fri, 30 Aug 2019, Anthony Walter via lazarus wrote:
> Alan, oh that's a good idea. I will do that as well as add a few more
> parser libraries as requested by a few people in other non mailing lists
> threads. I will also try to find out what's going on the unicode strings as
> it might be a problem with the compiler.
>
> Michael,
>
> I am on Linux as well, but I will test under Windows and Mac too.
To show that my argument of 'coding proficiency' influence on algorithm
speed is not complete nonsense, I quickly cooked up the following test:
{$mode objfpc}
{$h+}
uses DateUtils, Sysutils,Classes, fpjson, jsonparser;
var
FN : String;
i,aCount : Integer;
S : TJSONStringType;
T : TMemoryStream;
N : TDateTime;
procedure ReadJSON;
begin
T:=TMemoryStream.Create;
T.LoadFromFile(FN);
SetLength(S,T.Size);
T.ReadBuffer(S[1],T.Size);
T.Position:=0;
end;
begin
if ParamCount<>2 then Halt(1);
aCount:=StrToInt(Paramstr(1));
FN:=ParamStr(2);
ReadJSON;
try
Writeln('Reading string ',aCount,' times');
N:=Now;
for I:=1 to aCount do
GetJSON(S).Free;
Writeln('Msecs : ',MillisecondsBetween(Now,N));
Writeln('Reading stream ',aCount,' times');
N:=Now;
for I:=1 to aCount do
begin
GetJSON(T).Free;
T.Position:=0;
end;
Writeln('Msecs : ',MillisecondsBetween(Now,N));
finally
T.Free;
end;
end.
When you run this:
home:~/fpc/packages/fcl-json/tests> ./testjsonspeedread 100 ./testdata.json
Reading string 100 times
Msecs : 2972
Reading stream 100 times
Msecs : 1203
(file of 260Kb, 500 lines)
Not using a string (as you do) but a stream already gives a factor of 2.x faster.
The speed gain is there both for trunk as for 3.0.4.
So, I'm fairly confident that I can probably speed up your test results as
well, when you send me the sources.
That said, this is not to say that there is no room for speed improvements in fpjson.
I've already identified 2 places where speed gains can be made in the fpJSON
codebase, I'll improve the codebase this weekend and post results.
Michael.
More information about the fpc-pascal
mailing list