Skip to content

Commit 54e9ccd

Browse files
committed
Merge branch 'main' of github.com:gcarreno/1brc-ObjectPascal
2 parents daf2758 + 42b1b7c commit 54e9ccd

File tree

11 files changed

+40
-72
lines changed

11 files changed

+40
-72
lines changed

baseline/Common/baseline.common.pas

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,20 @@ function RoundExInteger(const ATemp: Double): Integer;
1515

1616
implementation
1717

18-
function Ceiling(const ANumber: Double): integer;
18+
function Ceiling(const ANumber: Double): integer; inline;
1919
begin
2020
Result := Trunc(ANumber) + Ord(Frac(ANumber) > 0);
2121
end;
2222

23-
function RoundExDouble(const ATemp: Double): Double;
23+
function RoundExDouble(const ATemp: Double): Double; inline;
2424
var
2525
tmp: Double;
2626
begin
2727
tmp:= ATemp * 10;
2828
Result := Ceiling(tmp) / 10;
2929
end;
3030

31-
function RoundExInteger(const ATemp: Double): Integer;
31+
function RoundExInteger(const ATemp: Double): Integer; inline;
3232
var
3333
tmp: Double;
3434
begin

entries/ikelaiah/src/OneBRC.lpi

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
</Target>
2727
<SearchPaths>
2828
<IncludeFiles Value="$(ProjOutDir)"/>
29+
<OtherUnitFiles Value="..\..\..\baseline\Common"/>
2930
<UnitOutputDirectory Value="..\..\..\bin\lib\$(TargetCPU)-$(TargetOS)"/>
3031
</SearchPaths>
3132
<Parsing>
@@ -68,6 +69,7 @@
6869
</Target>
6970
<SearchPaths>
7071
<IncludeFiles Value="$(ProjOutDir)"/>
72+
<OtherUnitFiles Value="..\..\..\baseline\Common"/>
7173
<UnitOutputDirectory Value="..\..\..\bin\lib\$(TargetCPU)-$(TargetOS)"/>
7274
</SearchPaths>
7375
<CodeGeneration>
@@ -83,6 +85,11 @@
8385
</Debugging>
8486
<LinkSmart Value="True"/>
8587
</Linking>
88+
<Other>
89+
<OtherDefines Count="1">
90+
<Define0 Value="DEBUG"/>
91+
</OtherDefines>
92+
</Other>
8693
</CompilerOptions>
8794
</Item3>
8895
</BuildModes>
@@ -123,6 +130,7 @@
123130
</Target>
124131
<SearchPaths>
125132
<IncludeFiles Value="$(ProjOutDir)"/>
133+
<OtherUnitFiles Value="..\..\..\baseline\Common"/>
126134
<UnitOutputDirectory Value="..\..\..\bin\lib\$(TargetCPU)-$(TargetOS)"/>
127135
</SearchPaths>
128136
<CodeGeneration>

entries/ikelaiah/src/weatherstation.pas

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ interface
1313
{$IFDEF DEBUG}
1414
, Stopwatch
1515
{$ENDIF}
16+
, Baseline.Common
1617
;
1718

1819
type
@@ -46,33 +47,6 @@ procedure ProcessTempMeasurementsV4a(const filename: string);
4647

4748
implementation
4849

49-
function RoundEx(x: Double): Double; inline;
50-
begin
51-
Result := Ceil(x * 10) / 10;
52-
end;
53-
54-
function RoundExInteger(x: Double): Integer; inline;
55-
begin
56-
Result := Ceil(x * 10);
57-
end;
58-
59-
function RoundExString(x: Double): String; inline;
60-
var
61-
V, Q, R: Integer;
62-
begin
63-
V := RoundExInteger(x);
64-
if V < 0 then
65-
begin
66-
Result := '-';
67-
V := -V;
68-
end
69-
else
70-
Result := '';
71-
Q := V div 10;
72-
R := V - (Q * 10);
73-
Result := IntToStr(Q) + '.' + IntToStr(R);
74-
end;
75-
7650
constructor TStat.Create(const newMin: int64; const newMax: int64;
7751
const newSum: int64; const newCount: int64);
7852
begin
@@ -86,9 +60,9 @@ function TStat.ToString: string;
8660
var
8761
minR, meanR, maxR: double; // Store the rounded values prior saving to TStringList.
8862
begin
89-
minR := RoundEx(self.min / 10);
90-
maxR := RoundEx(self.max / 10);
91-
meanR := RoundEx(self.sum / self.cnt / 10);
63+
minR := RoundExDouble(self.min / 10);
64+
maxR := RoundExDouble(self.max / 10);
65+
meanR := RoundExDouble(self.sum / self.cnt / 10);
9266
Result := FormatFloat('0.0', minR) + '/' + FormatFloat('0.0', meanR) +
9367
'/' + FormatFloat('0.0', maxR);
9468
end;

entries/laksen/src/laksen.lpi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
</Target>
2525
<SearchPaths>
2626
<IncludeFiles Value="$(ProjOutDir)"/>
27+
<OtherUnitFiles Value="../../../baseline/Common"/>
2728
<UnitOutputDirectory Value="../../../bin/lib/$(TargetCPU)-$(TargetOS)"/>
2829
</SearchPaths>
2930
<CodeGeneration>
@@ -63,6 +64,7 @@
6364
</Target>
6465
<SearchPaths>
6566
<IncludeFiles Value="$(ProjOutDir)"/>
67+
<OtherUnitFiles Value="../../../baseline/Common"/>
6668
<UnitOutputDirectory Value="../../../bin/lib/$(TargetCPU)-$(TargetOS)"/>
6769
</SearchPaths>
6870
<Parsing>

entries/laksen/src/laksen.lpr

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
SysUtils,
88
Classes,
99
Contnrs,
10-
Math;
10+
Math,
11+
Baseline.Common;
1112

1213
type
1314

@@ -291,30 +292,9 @@ TParser = class
291292
Threads[i].Free;
292293
end;
293294

294-
function PascalRound(x: double): double;
295-
var
296-
t: double;
297-
begin
298-
//round towards positive infinity
299-
t := Trunc(x);
300-
if (x<0.0) and (t-x = 0.5) then
301-
begin
302-
// Do nothing
303-
end
304-
else if Abs(x-t)>=0.5 then
305-
begin
306-
t := t+Math.Sign(x);
307-
end;
308-
309-
if t = 0.0 then
310-
Result := 0.0
311-
else
312-
Result := t;
313-
end;
314-
315295
function AsNum(AValue, ACount: longint): string;
316296
begin
317-
Result := formatfloat('0.0', PascalRound(AValue/ACount)/10);
297+
Result := formatfloat('0.0', RoundExDouble(AValue/ACount)/10);
318298
end;
319299

320300
procedure TParser.Dump;

entries/rlawson/src/parser.pas

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
interface
66

77
uses
8-
Classes, SysUtils, bufstream, Contnrs, Math, util;
8+
Classes, SysUtils, bufstream, Contnrs, Math, util, Baseline.Common;
99

1010
procedure ReadMeasurements(inputFile: string);
1111

@@ -109,9 +109,9 @@ procedure DumpMeasurements(results: TFPHashList);
109109
for i := 0 to results.Count - 1 do
110110
begin
111111
reading := results.Items[i];
112-
min := RoundEx(reading^.min / 10);
113-
max := RoundEx(reading^.max / 10);
114-
mean := RoundEx(reading^.total / reading^.numReadings / 10);
112+
min := RoundExDouble(reading^.min / 10);
113+
max := RoundExDouble(reading^.max / 10);
114+
mean := RoundExDouble(reading^.total / reading^.numReadings / 10);
115115
readingStr := reading^.city + '=' + FormatFloat('0.0', min) +
116116
'/' + FormatFloat('0.0', mean) + '/' + FormatFloat('0.0', max);
117117
weatherStationList.Add(readingStr);

entries/rlawson/src/util.pas

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ interface
88
Classes, SysUtils, Math;
99

1010
procedure DumpExceptionCallStack(E: Exception);
11-
function RoundEx(x: double): double;
1211
function Compare(AList: TStringList; AIndex1, AIndex2: integer): integer;
1312

1413
implementation

entries/rlawson/src/weather.lpi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
</Target>
2525
<SearchPaths>
2626
<IncludeFiles Value="$(ProjOutDir)"/>
27+
<OtherUnitFiles Value="../../../baseline/Common"/>
2728
<UnitOutputDirectory Value="../../../bin/lib/$(TargetCPU)-$(TargetOS)"/>
2829
</SearchPaths>
2930
<Parsing>
@@ -58,6 +59,7 @@
5859
</Target>
5960
<SearchPaths>
6061
<IncludeFiles Value="$(ProjOutDir)"/>
62+
<OtherUnitFiles Value="../../../baseline/Common"/>
6163
<UnitOutputDirectory Value="../../../bin/lib/$(TargetCPU)-$(TargetOS)"/>
6264
</SearchPaths>
6365
<CodeGeneration>
@@ -105,6 +107,7 @@
105107
</Target>
106108
<SearchPaths>
107109
<IncludeFiles Value="$(ProjOutDir)"/>
110+
<OtherUnitFiles Value="../../../baseline/Common"/>
108111
<UnitOutputDirectory Value="../../../bin/lib/$(TargetCPU)-$(TargetOS)"/>
109112
</SearchPaths>
110113
<Linking>

entries/sbalazs/src/obrc.lpi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
</Target>
2727
<SearchPaths>
2828
<IncludeFiles Value="$(ProjOutDir)"/>
29+
<OtherUnitFiles Value="..\..\..\baseline\Common"/>
2930
<UnitOutputDirectory Value="..\..\..\bin\lib\$(TargetCPU)-$(TargetOS)"/>
3031
</SearchPaths>
3132
<Parsing>
@@ -66,6 +67,7 @@
6667
</Target>
6768
<SearchPaths>
6869
<IncludeFiles Value="$(ProjOutDir)"/>
70+
<OtherUnitFiles Value="..\..\..\baseline\Common"/>
6971
<UnitOutputDirectory Value="..\..\..\bin\lib\$(TargetCPU)-$(TargetOS)"/>
7072
</SearchPaths>
7173
<CodeGeneration>
@@ -116,6 +118,7 @@
116118
</Target>
117119
<SearchPaths>
118120
<IncludeFiles Value="$(ProjOutDir)"/>
121+
<OtherUnitFiles Value="..\..\..\baseline\Common"/>
119122
<UnitOutputDirectory Value="..\..\..\bin\lib\$(TargetCPU)-$(TargetOS)"/>
120123
</SearchPaths>
121124
<Linking>

entries/sbalazs/src/uweatherstations.pas

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
interface
88

99
uses
10-
{$IFDEF MSWINDOWS}Windows, {$ENDIF}Classes, SysUtils, Math, syncobjs;
10+
{$IFDEF MSWINDOWS}Windows, {$ENDIF}Classes, SysUtils, Math, syncobjs, Baseline.Common;
1111

1212
const
1313
HashBuckets = 1 shl 17;
@@ -84,7 +84,6 @@ TWSThread = class(TWSThreadBase)
8484

8585
TWSThreadsWatcher = class(TWSThreadBase)
8686
private
87-
function RoundEx(x: Double): Double; inline;
8887
procedure CreateFinalList;
8988
protected
9089
procedure Execute; override;
@@ -471,11 +470,6 @@ function Compare(List: TStringList; Index1, Index2: Integer): Integer;
471470
end;
472471
end;
473472

474-
function TWSThreadsWatcher.RoundEx(x: Double): Double; inline;
475-
begin
476-
Result := Ceil(x * 10) / 10;
477-
end;
478-
479473
procedure TWSThreadsWatcher.CreateFinalList;
480474
var
481475
I: Integer;
@@ -501,7 +495,7 @@ procedure TWSThreadsWatcher.CreateFinalList;
501495
SetCodePage(Name, CP_UTF8, True);
502496
Min := WS.FData.FMin/10;
503497
Max := WS.FData.FMax/10;
504-
Mean := RoundEx(WS.FData.FTot/WS.FData.FCnt/10);
498+
Mean := RoundExDouble(WS.FData.FTot/WS.FData.FCnt/10);
505499
Str := Name + '=' + FormatFloat('0.0', Min) + '/' + FormatFloat('0.0', Mean) + '/' + FormatFloat('0.0', Max) + ',';
506500
SL.Add(Str);
507501
end;

0 commit comments

Comments
 (0)