From 67f606f4821c926b6b7dc96fca9e50dc3f3999ac Mon Sep 17 00:00:00 2001 From: Georges Hatem Date: Fri, 26 Apr 2024 15:45:08 +0300 Subject: [PATCH 1/2] add ValGrind configuration --- entries/ghatem-fpc/src/OneBRCproj.lpi | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/entries/ghatem-fpc/src/OneBRCproj.lpi b/entries/ghatem-fpc/src/OneBRCproj.lpi index 5b60f40..310cdad 100644 --- a/entries/ghatem-fpc/src/OneBRCproj.lpi +++ b/entries/ghatem-fpc/src/OneBRCproj.lpi @@ -15,7 +15,7 @@ - + @@ -84,6 +84,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + From 82d1f503bd8f6adf61ff45d1402ac9c2b1e4391d Mon Sep 17 00:00:00 2001 From: Georges Hatem Date: Fri, 26 Apr 2024 22:51:03 +0300 Subject: [PATCH 2/2] parameter -s to specify the dictionary size --- entries/ghatem-fpc/src/OneBRCproj.lpr | 12 ++++++++++-- entries/ghatem-fpc/src/baseline.console.pas | 2 ++ entries/ghatem-fpc/src/onebrc.pas | 8 ++++++-- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/entries/ghatem-fpc/src/OneBRCproj.lpr b/entries/ghatem-fpc/src/OneBRCproj.lpr index 91d6af5..4c68867 100644 --- a/entries/ghatem-fpc/src/OneBRCproj.lpr +++ b/entries/ghatem-fpc/src/OneBRCproj.lpr @@ -18,6 +18,7 @@ TOneBRCApp = class(TCustomApplication) private FFileName: string; FThreadCount: Integer; + FDictSize: Integer; procedure RunOneBRC; protected procedure DoRun; override; @@ -33,7 +34,7 @@ procedure TOneBRCApp.RunOneBRC; var vOneBRC: TOneBRC; begin - vOneBRC := TOneBRC.Create (FThreadCount); + vOneBRC := TOneBRC.Create (FThreadCount, FDictSize); try try vOneBRC.mORMotMMF(FFileName); @@ -88,15 +89,17 @@ procedure TOneBRCApp.DoRun; ErrorMsg: String; begin // quick check parameters - ErrorMsg:= CheckOptions(Format('%s%s%s%s:',[ + ErrorMsg:= CheckOptions(Format('%s%s%s%s%s:',[ cShortOptHelp, cShortOptThread, + cShortOptDictSize, cShortOptVersion, cShortOptInput ]), [ cLongOptHelp, cLongOptThread+':', + cLongOptDictSize+':', cLongOptVersion, cLongOptInput+':' ] @@ -126,6 +129,11 @@ procedure TOneBRCApp.DoRun; FThreadCount := StrToInt (GetOptionValue(cShortOptThread, cLongOptThread)); end; + FDictSize := 45003; + if HasOption(cShortOptDictSize, cLongOptDictSize) then begin + FDictSize := StrToInt (GetOptionValue(cShortOptDictSize, cLongOptDictSize)); + end; + if HasOption(cShortOptInput, cLongOptInput) then begin FFileName := GetOptionValue( cShortOptInput, diff --git a/entries/ghatem-fpc/src/baseline.console.pas b/entries/ghatem-fpc/src/baseline.console.pas index bf961c0..6ef14c8 100644 --- a/entries/ghatem-fpc/src/baseline.console.pas +++ b/entries/ghatem-fpc/src/baseline.console.pas @@ -21,6 +21,8 @@ interface cLongOptInput = 'input-file'; cShortOptThread: Char = 't'; cLongOptThread = 'threads'; + cShortOptDictSize: Char = 's'; + cLongOptDictSize = 'size'; {$ELSE} cOptionHelp: array of string = ['-h', '--help']; cOptionVersion: array of string = ['-v', '--version']; diff --git a/entries/ghatem-fpc/src/onebrc.pas b/entries/ghatem-fpc/src/onebrc.pas index a1afa94..c336858 100644 --- a/entries/ghatem-fpc/src/onebrc.pas +++ b/entries/ghatem-fpc/src/onebrc.pas @@ -10,8 +10,10 @@ interface function RoundExDouble(const ATemp: Double): Double; inline; +{$WRITEABLECONST ON} const cDictSize: Integer = 45003; +{$WRITEABLECONST OFF} type @@ -63,7 +65,7 @@ TOneBRC = class procedure ExtractLineData(const aStart: Int64; const aEnd: Int64; out aLength: ShortInt; out aTemp: SmallInt); inline; public - constructor Create (const aThreadCount: UInt16); + constructor Create (const aThreadCount: UInt16; const aDictSize: Integer); destructor Destroy; override; function mORMotMMF (const afilename: string): Boolean; procedure DispatchThreads; @@ -249,9 +251,11 @@ procedure TOneBRC.ExtractLineData(const aStart: Int64; const aEnd: Int64; out aL //--------------------------------------------------- -constructor TOneBRC.Create (const aThreadCount: UInt16); +constructor TOneBRC.Create (const aThreadCount: UInt16; const aDictSize: Integer); var I: UInt16; begin + cDictSize := aDictSize; + FThreadCount := aThreadCount; SetLength (FStationsDicts, aThreadCount); SetLength (FThreads, aThreadCount);