Skip to content

Commit f024f6b

Browse files
committed
ghatem FPC implementation...
1 parent 7dd69e0 commit f024f6b

File tree

4 files changed

+697
-0
lines changed

4 files changed

+697
-0
lines changed
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
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+
</Flags>
12+
<SessionStorage Value="InProjectDir"/>
13+
<Title Value="1 BRC"/>
14+
<UseAppBundle Value="False"/>
15+
<ResourceType Value="res"/>
16+
</General>
17+
<BuildModes>
18+
<Item Name="Default" Default="True"/>
19+
<Item Name="Debug">
20+
<CompilerOptions>
21+
<Version Value="11"/>
22+
<PathDelim Value="\"/>
23+
<Target>
24+
<Filename Value="OneBRCproj"/>
25+
</Target>
26+
<SearchPaths>
27+
<IncludeFiles Value="$(ProjOutDir)"/>
28+
<OtherUnitFiles Value="C:\DelphiLibs\Mormot\mORMot2-master\src\core\"/>
29+
<UnitOutputDirectory Value="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+
</Item>
55+
<Item Name="Release">
56+
<CompilerOptions>
57+
<Version Value="11"/>
58+
<PathDelim Value="\"/>
59+
<Target>
60+
<Filename Value="OneBRCproj"/>
61+
</Target>
62+
<SearchPaths>
63+
<IncludeFiles Value="$(ProjOutDir)"/>
64+
<OtherUnitFiles Value="C:\DelphiLibs\Mormot\mORMot2-master\src\core\"/>
65+
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
66+
</SearchPaths>
67+
<CodeGeneration>
68+
<SmartLinkUnit Value="True"/>
69+
<Optimizations>
70+
<OptimizationLevel Value="3"/>
71+
</Optimizations>
72+
</CodeGeneration>
73+
<Linking>
74+
<Debugging>
75+
<GenerateDebugInfo Value="False"/>
76+
<RunWithoutDebug Value="True"/>
77+
</Debugging>
78+
<LinkSmart Value="True"/>
79+
</Linking>
80+
</CompilerOptions>
81+
</Item>
82+
</BuildModes>
83+
<PublishOptions>
84+
<Version Value="2"/>
85+
<UseFileFilters Value="True"/>
86+
</PublishOptions>
87+
<RunParams>
88+
<FormatVersion Value="2"/>
89+
</RunParams>
90+
<RequiredPackages>
91+
<Item>
92+
<PackageName Value="LCLBase"/>
93+
</Item>
94+
</RequiredPackages>
95+
<Units>
96+
<Unit>
97+
<Filename Value="OneBRCproj.lpr"/>
98+
<IsPartOfProject Value="True"/>
99+
</Unit>
100+
<Unit>
101+
<Filename Value="onebrc.pas"/>
102+
<IsPartOfProject Value="True"/>
103+
<UnitName Value="OneBRC"/>
104+
</Unit>
105+
</Units>
106+
</ProjectOptions>
107+
<CompilerOptions>
108+
<Version Value="11"/>
109+
<PathDelim Value="\"/>
110+
<Target>
111+
<Filename Value="OneBRCproj"/>
112+
</Target>
113+
<SearchPaths>
114+
<IncludeFiles Value="$(ProjOutDir)"/>
115+
<OtherUnitFiles Value="C:\DelphiLibs\Mormot\mORMot2-master\src\core\"/>
116+
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
117+
</SearchPaths>
118+
<Linking>
119+
<Debugging>
120+
<DebugInfoType Value="dsDwarf3"/>
121+
</Debugging>
122+
</Linking>
123+
</CompilerOptions>
124+
<Debugging>
125+
<Exceptions>
126+
<Item>
127+
<Name Value="EAbort"/>
128+
</Item>
129+
<Item>
130+
<Name Value="ECodetoolError"/>
131+
</Item>
132+
<Item>
133+
<Name Value="EFOpenError"/>
134+
</Item>
135+
</Exceptions>
136+
</Debugging>
137+
</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)