[Lazarus] [fpc-pascal] Tests results of several pascal based JSON parsers
Anthony Walter
sysrpl at gmail.com
Fri Aug 30 19:57:36 CEST 2019
I am not sure how under any situation parsing a JSON from a stream source
would be any faster than parsing a string. Also with regards to timing I am
not sure how accurate Now is. For this purpose I've written:
{ Return a time based on system performance counters }
function TimeQuery: Double;
Implemented as:
const
{$ifdef linux}
libc = 'libc.so';
{$endif}
{$ifdef darwin}
libc = 'libSystem.dylib';
{$endif}
function gettimeofday(out TimeVal: TTimeVal; TimeZone: PTimeVal): Integer;
apicall; external libc;
var
TimeSec: SysInt;
function TimeQuery: Double;
var
TimeVal: TTimeVal;
begin
gettimeofday(TimeVal, nil);
if TimeSec = 0 then
TimeSec := TimeVal.Sec;
TimeVal.Sec := TimeVal.Sec - TimeSec;
Result := TimeVal.Sec + TimeVal.MSec / 1000000;
end;
{$endif}
{$ifdef windows}
const
kernel32 = 'kernel32.dll';
function QueryPerformanceCounter(var Counter: Int64): LongBool; apicall;
external kernel32;
function QueryPerformanceFrequency(var Frequency: Int64): LongBool;
apicall; external kernel32;
function TimeQuery: Double;
var
C, F: Int64;
begin
F := 0;
C := 0;
if QueryPerformanceFrequency(F) and QueryPerformanceCounter(C) then
Result := C / F
else
Result := 0;
end;
{$endif}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20190830/3c5a24a3/attachment.html>
More information about the lazarus
mailing list