diff --git a/entries/ghatem-fpc/src/OneBRC.lpr b/entries/ghatem-fpc/src/OneBRC.lpr index cbf75af..5b7486d 100644 --- a/entries/ghatem-fpc/src/OneBRC.lpr +++ b/entries/ghatem-fpc/src/OneBRC.lpr @@ -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 @@ -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 @@ -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); @@ -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);