Skip to content

Commit edff39f

Browse files
authored
Merge pull request #93 from georges-hatem/main
ghatem FPC implementation
2 parents 7dd69e0 + 7cc28a7 commit edff39f

File tree

4 files changed

+698
-0
lines changed

4 files changed

+698
-0
lines changed
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<CONFIG>
3+
<ProjectOptions>
4+
<Version Value="12"/>
5+
<PathDelim Value="\"/>
6+
<General>
7+
<Flags>
8+
<MainUnitHasCreateFormStatements Value="False"/>
9+
<MainUnitHasTitleStatement Value="False"/>
10+
<MainUnitHasScaledStatement Value="False"/>
11+
<CompatibilityMode Value="True"/>
12+
</Flags>
13+
<SessionStorage Value="InProjectDir"/>
14+
<Title Value="1 BRC"/>
15+
<UseAppBundle Value="False"/>
16+
<ResourceType Value="res"/>
17+
</General>
18+
<BuildModes Count="3">
19+
<Item1 Name="Default" Default="True"/>
20+
<Item2 Name="Debug">
21+
<CompilerOptions>
22+
<Version Value="11"/>
23+
<PathDelim Value="\"/>
24+
<Target>
25+
<Filename Value="..\..\..\bin\ghatem"/>
26+
</Target>
27+
<SearchPaths>
28+
<IncludeFiles Value="$(ProjOutDir)"/>
29+
<UnitOutputDirectory Value="..\..\..\bin\lib\$(TargetCPU)-$(TargetOS)"/>
30+
</SearchPaths>
31+
<Parsing>
32+
<SyntaxOptions>
33+
<IncludeAssertionCode Value="True"/>
34+
</SyntaxOptions>
35+
</Parsing>
36+
<CodeGeneration>
37+
<Checks>
38+
<IOChecks Value="True"/>
39+
<RangeChecks Value="True"/>
40+
<OverflowChecks Value="True"/>
41+
<StackChecks Value="True"/>
42+
</Checks>
43+
<VerifyObjMethodCallValidity Value="True"/>
44+
</CodeGeneration>
45+
<Linking>
46+
<Debugging>
47+
<DebugInfoType Value="dsDwarf3"/>
48+
<UseHeaptrc Value="True"/>
49+
<TrashVariables Value="True"/>
50+
<UseExternalDbgSyms Value="True"/>
51+
</Debugging>
52+
</Linking>
53+
</CompilerOptions>
54+
</Item2>
55+
<Item3 Name="Release">
56+
<CompilerOptions>
57+
<Version Value="11"/>
58+
<PathDelim Value="\"/>
59+
<Target>
60+
<Filename Value="..\..\..\bin\ghatem"/>
61+
</Target>
62+
<SearchPaths>
63+
<IncludeFiles Value="$(ProjOutDir)"/>
64+
<UnitOutputDirectory Value="..\..\..\bin\lib\$(TargetCPU)-$(TargetOS)"/>
65+
</SearchPaths>
66+
<CodeGeneration>
67+
<SmartLinkUnit Value="True"/>
68+
<Optimizations>
69+
<OptimizationLevel Value="3"/>
70+
</Optimizations>
71+
</CodeGeneration>
72+
<Linking>
73+
<Debugging>
74+
<GenerateDebugInfo Value="False"/>
75+
<RunWithoutDebug Value="True"/>
76+
</Debugging>
77+
<LinkSmart Value="True"/>
78+
</Linking>
79+
</CompilerOptions>
80+
</Item3>
81+
</BuildModes>
82+
<PublishOptions>
83+
<Version Value="2"/>
84+
<UseFileFilters Value="True"/>
85+
</PublishOptions>
86+
<RunParams>
87+
<FormatVersion Value="2"/>
88+
</RunParams>
89+
<RequiredPackages Count="2">
90+
<Item1>
91+
<PackageName Value="mormot2"/>
92+
</Item1>
93+
<Item2>
94+
<PackageName Value="LCLBase"/>
95+
</Item2>
96+
</RequiredPackages>
97+
<Units Count="2">
98+
<Unit0>
99+
<Filename Value="OneBRCproj.lpr"/>
100+
<IsPartOfProject Value="True"/>
101+
</Unit0>
102+
<Unit1>
103+
<Filename Value="onebrc.pas"/>
104+
<IsPartOfProject Value="True"/>
105+
<UnitName Value="OneBRC"/>
106+
</Unit1>
107+
</Units>
108+
</ProjectOptions>
109+
<CompilerOptions>
110+
<Version Value="11"/>
111+
<PathDelim Value="\"/>
112+
<Target>
113+
<Filename Value="..\..\..\bin\ghatem"/>
114+
</Target>
115+
<SearchPaths>
116+
<IncludeFiles Value="$(ProjOutDir)"/>
117+
<UnitOutputDirectory Value="..\..\..\bin\lib\$(TargetCPU)-$(TargetOS)"/>
118+
</SearchPaths>
119+
<Linking>
120+
<Debugging>
121+
<DebugInfoType Value="dsDwarf3"/>
122+
</Debugging>
123+
</Linking>
124+
</CompilerOptions>
125+
<Debugging>
126+
<Exceptions Count="3">
127+
<Item1>
128+
<Name Value="EAbort"/>
129+
</Item1>
130+
<Item2>
131+
<Name Value="ECodetoolError"/>
132+
</Item2>
133+
<Item3>
134+
<Name Value="EFOpenError"/>
135+
</Item3>
136+
</Exceptions>
137+
</Debugging>
138+
</CONFIG>
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
program OneBRCproj;
2+
3+
{$mode objfpc}{$H+}
4+
5+
uses
6+
{$IFDEF UNIX}
7+
cthreads,
8+
{$ENDIF}
9+
Classes, SysUtils, CustApp, Lclintf,
10+
Baseline.Console,
11+
OneBRC;
12+
13+
type
14+
15+
{ TOneBRCApp }
16+
17+
TOneBRCApp = class(TCustomApplication)
18+
private
19+
protected
20+
procedure DoRun; override;
21+
public
22+
constructor Create(TheOwner: TComponent); override;
23+
destructor Destroy; override;
24+
procedure WriteHelp; virtual;
25+
end;
26+
27+
{ TOneBRCApp }
28+
29+
procedure TOneBRCApp.DoRun;
30+
var
31+
ErrorMsg: String;
32+
vOneBRC: TOneBRC;
33+
vFileName: string;
34+
vStart: Int64;
35+
vTime: Int64;
36+
begin
37+
// quick check parameters
38+
ErrorMsg:= CheckOptions(Format('%s%s%s:',[
39+
cShortOptHelp,
40+
cShortOptVersion,
41+
cShortOptInput
42+
]),
43+
[
44+
cLongOptHelp,
45+
cLongOptVersion,
46+
cLongOptInput+':'
47+
]
48+
);
49+
if ErrorMsg<>'' then begin
50+
//ShowException(Exception.Create(ErrorMsg));
51+
WriteLn(Format(rsErrorMessage, [ ErrorMsg ]));
52+
Terminate;
53+
Exit;
54+
end;
55+
56+
// parse parameters
57+
if HasOption(cShortOptHelp, cLongOptHelp) then begin
58+
WriteHelp;
59+
Terminate;
60+
Exit;
61+
end;
62+
63+
if HasOption(cShortOptVersion, cLongOptVersion) then begin
64+
WriteLn(Format(rsGeneratorVersion, [ cVersion ]));
65+
Terminate;
66+
Exit;
67+
end;
68+
69+
if HasOption(cShortOptInput, cLongOptInput) then begin
70+
vFileName := GetOptionValue(
71+
cShortOptInput,
72+
cLongOptInput
73+
);
74+
end
75+
else begin
76+
WriteLn(Format(rsErrorMessage, [ rsMissingInputFlag ]));
77+
Terminate;
78+
Exit;
79+
end;
80+
81+
vFileName := ExpandFileName(vFileName);
82+
83+
vOneBRC := TOneBRC.Create;
84+
try
85+
try
86+
//vOneBRC.mORMotMMF(vFileName);
87+
//vOneBRC.SingleThread;
88+
//vOneBRC.GenerateOutput;
89+
//vOneBRC.Free;
90+
91+
vStart := GetTickCount;
92+
vOneBRC.mORMotMMF (vFileName);
93+
vTime := GetTickCount - vStart;
94+
WriteLn('read: ' + FloatToStr(vTime / 1000));
95+
WriteLn('-----------');
96+
WriteLn;
97+
98+
vStart := GetTickCount;
99+
vOneBRC.SingleThread;
100+
vTime := GetTickCount - vStart;
101+
WriteLn('process: ' + FloatToStr(vTime / 1000));
102+
WriteLn('-----------');
103+
WriteLn;
104+
105+
106+
107+
vStart := GetTickCount;
108+
vOneBRC.GenerateOutput;
109+
vTime := GetTickCount - vStart;
110+
WriteLn('generate: ' + FloatToStr(vTime / 1000));
111+
WriteLn('-----------');
112+
WriteLn;
113+
ReadLn;
114+
except
115+
on E: Exception do
116+
begin
117+
WriteLn(Format(rsErrorMessage, [ E.Message ]));
118+
end;
119+
end;
120+
finally
121+
vOneBRC.Free;
122+
end;
123+
124+
// stop program loop
125+
Terminate;
126+
end;
127+
128+
constructor TOneBRCApp.Create(TheOwner: TComponent);
129+
begin
130+
inherited Create(TheOwner);
131+
StopOnException:=True;
132+
end;
133+
134+
destructor TOneBRCApp.Destroy;
135+
begin
136+
inherited Destroy;
137+
end;
138+
139+
procedure TOneBRCApp.WriteHelp;
140+
begin
141+
{ add your help code here }
142+
writeln('Usage: ', ExeName, ' -h');
143+
end;
144+
145+
var
146+
Application: TOneBRCApp;
147+
begin
148+
Application:=TOneBRCApp.Create(nil);
149+
Application.Title:='1 BRC';
150+
Application.Run;
151+
Application.Free;
152+
end.
153+

0 commit comments

Comments
 (0)