Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 22 additions & 11 deletions entries/ghatem-fpc/src/OneBRC.lpr
Original file line number Diff line number Diff line change
Expand Up @@ -465,8 +465,21 @@ procedure TOneBRC.ProcessData (aThreadNb: TThreadCount; aStartIdx: Int64; aEndId
Inc (I, 5);
end;

while FData[i] <> #10 do begin
Inc (I);
// unroll a few seems to be improving?
if FData[i] <> #10 then begin
Inc (i);
if FData[i] <> #10 then begin
Inc (i);
if FData[i] <> #10 then begin
Inc (I);
if FData[i] <> #10 then begin
Inc (i);
while FData[i] <> #10 do begin
Inc (I);
end;
end;
end;
end;
end;

// new line parsed, process its contents
Expand Down Expand Up @@ -563,13 +576,11 @@ function MyFormatInt (const aIn: SmallInt): AnsiString; inline;
//---------------------------------------------------

procedure TOneBRC.GenerateOutput;
var vMean: Integer;
vStream: TStringStream;
I, N: Int64;
var vStream: TStringStream;
I, N: Int32;
vData: PStationData;
vHash: Cardinal;
vStations: TStringList;
iStationName: AnsiString;
vIdx: THashSize;
vRes: Boolean;
begin
Expand All @@ -579,9 +590,11 @@ procedure TOneBRC.GenerateOutput;
vStations.UseLocale := False;
try
vStations.BeginUpdate;
for iStationName in FDictionary.FStationNames do begin
vStations.Add(iStationName);
for i := 0 to cNumStations - 1 do begin
if FDictionary.FStationNames[i] <> '' then
vStations.Add (FDictionary.FStationNames[i]);
end;

vStations.EndUpdate;
vStations.CustomSort (@Compare);

Expand All @@ -598,11 +611,9 @@ procedure TOneBRC.GenerateOutput;
FDictionary.InternalFind (vHash, vRes, vIdx);
vData := @FDictionary.FThreadData[0][FDictionary.FIndexes[vIdx]];

vMean := RoundExInteger(vData^.Sum/vData^.Count/10);

vStream.WriteString(
vStations[i] + '=' + MyFormatInt(vData^.Min)
+ '/' + MyFormatInt(vMean)
+ '/' + MyFormatInt(RoundExInteger(vData^.Sum/vData^.Count/10))
+ '/' + MyFormatInt(vData^.Max) + ', '
);
Inc(I);
Expand Down