Skip to content

Commit d63fa59

Browse files
authored
Merge branch 'gcarreno:main' into main
2 parents 3ecfd43 + 4f35014 commit d63fa59

File tree

6 files changed

+32
-49
lines changed

6 files changed

+32
-49
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ Expected `SHA256` hash:
145145
> We are still waiting for the Delphi version to be completed in order for us to have an official `SHA256` hash for the output.
146146
>
147147
> Until then, this is the current one: `db3d79d31b50daa8c03a1e4f2025029cb137f9971aa04129d8bca004795ae524`
148+
> There's also an archived version of the [baseline output](./data/baseline.output.gz)
148149
149150
## Results
150151
These are the results from running all entries into the challenge on my personal computer:

data/baseline.output.gz

473 KB
Binary file not shown.

entries/entries.json.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"output-hash": "0000000000000000000000000000000000000000000000000000000000000000",
1111
"entries": [
1212
{
13+
"active": true,
1314
"name": "Official Baseline",
1415
"notes": "Beeing the last of all",
1516
"compiler": "fpc",
@@ -21,6 +22,7 @@
2122
"run-params": "-i [[input]]"
2223
},
2324
{
25+
"active": true,
2426
"name": "Gustavo Carreno",
2527
"notes": "Using 30 threads",
2628
"compiler": "fpc",

entries/sbalazs/src/uweatherstations.pas

Lines changed: 19 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
{$mode ObjFPC}{$H+}
44
{$R-} {$Q-}
5+
{$INLINE ON}
56

67
interface
78

@@ -14,7 +15,6 @@ interface
1415
type
1516
TWSManager = class;
1617

17-
type
1818
TData = record
1919
FMin: Int64;
2020
FMax: Int64;
@@ -70,11 +70,10 @@ TWSThread = class(TWSThreadBase)
7070
private
7171
FStartP: Int64;
7272
FEndP: Int64;
73-
FMS: TMemoryStream;
7473
FWSList: TWSList;
7574
procedure UpdateMainHashList;
76-
procedure ProcessBytes(ABytes: TBytes);
77-
procedure AddToHashList(AStation: TBytes; ATemp: Int64; AHash: QWord);
75+
procedure ProcessBytes(ABytes: TBytes); inline;
76+
procedure AddToHashList(ABytes: TBytes; AStartP, AEndP: Int64; ATemp: Int64; AHash: QWord);
7877
procedure UpdateThreadList(AUpdateType: TUpdateType);
7978
protected
8079
procedure Execute; override;
@@ -244,12 +243,10 @@ constructor TWSThread.Create(AStartP, AEndP: Int64; AWSManager: TWSManager);
244243
FStartP := AStartP;
245244
FEndP := AEndP;
246245
FStarted := False;
247-
FMS := TMemoryStream.Create;
248246
end;
249247

250248
destructor TWSThread.Destroy;
251249
begin
252-
FMS.Free;
253250
inherited Destroy;
254251
end;
255252

@@ -284,7 +281,6 @@ procedure TWSThread.ProcessBytes(ABytes: TBytes);
284281
PBeg: Int64;
285282
PDel: Int64;
286283
Len: Int64;
287-
Station: TBytes;
288284
Temp: Int64;
289285
DoHash: Boolean;
290286
DoTemp: Boolean;
@@ -295,7 +291,6 @@ procedure TWSThread.ProcessBytes(ABytes: TBytes);
295291
PBeg := 0;
296292
PDel := 0;
297293
Temp := 1000;
298-
Station := nil;
299294
DoHash := True;
300295
DoTemp := False;
301296
Len := Length(ABytes);
@@ -338,13 +333,10 @@ procedure TWSThread.ProcessBytes(ABytes: TBytes);
338333
end;
339334
if (ABytes[PCur] = 10) and (PCur < Len) then
340335
begin
341-
SetLength(Station, PDel - PBeg);
342-
Move(ABytes[PBeg], Station[0], PDel - PBeg);
343-
if (Station <> nil) and (Temp < 1000) then
344-
AddToHashList(Station, Temp, Hash);
336+
if (Temp < 1000) then
337+
AddToHashList(ABytes, PBeg, PDel, Temp, Hash);
345338
Hash := 14695981039346656037;
346339
DoHash := True;
347-
Station := nil;
348340
Temp := 1000;
349341
DoTemp := False;
350342
PBeg := PCur + 1;
@@ -354,12 +346,9 @@ procedure TWSThread.ProcessBytes(ABytes: TBytes);
354346

355347
procedure TWSThread.Execute;
356348
var
357-
ReadCnt: LongInt;
358-
Size: Int64;
359-
Bytes: TBytes;
360-
BytesEx: TBytes;
361-
Len, LenEx: LongInt;
362349
I: Integer;
350+
Bytes: TBytes;
351+
ReadCnt: LongInt;
363352
FS: TFileStream;
364353
begin
365354
UpdateThreadList(utAdd);
@@ -373,43 +362,24 @@ procedure TWSThread.Execute;
373362
FWSList[I].FData.FTot := 0;
374363
FWSList[I].FData.FCnt := 0;
375364
end;
365+
Bytes := nil;
376366
FS := TFileStream.Create(FWSManager.FSrcFile, fmOpenRead or fmShareDenyWrite);
377367
try
378368
FS.Position := FStartP;
379-
FMS.SetSize(FEndP - FStartP);
380-
FS.Read(FMS.Memory^, FEndP - FStartP);
381-
FMS.Position := 0;
369+
SetLength(Bytes, FEndP - FStartP);
370+
ReadCnt := FS.Read(Bytes[0], FEndP - FStartP);
371+
if ReadCnt > 0 then
372+
ProcessBytes(Bytes);
382373
finally
383374
FS.Free;
384375
end;
385-
Size := 1048576;
386-
repeat
387-
Bytes := nil;
388-
BytesEx := nil;
389-
if Size > FMS.Size - FMS.Position then
390-
Size := FMS.Size - FMS.Position;
391-
SetLength(Bytes, Size);
392-
ReadCnt := FMS.Read(Bytes[0], Size);
393-
if (ReadCnt > 0) then
394-
begin
395-
BytesEx := GetNextLineBreak(FMS);
396-
LenEx := Length(BytesEx);
397-
if LenEx > 0 then
398-
begin
399-
Len := Length(Bytes);
400-
SetLength(Bytes, Len + LenEx);
401-
Move(BytesEx[0], Bytes[Len], LenEx);
402-
end;
403-
AddLineBreak(Bytes);
404-
ProcessBytes(Bytes);
405-
end;
406-
until (ReadCnt = 0);
407376
finally
408377
UpdateThreadList(utRemove);
409378
end;
410379
end;
411380

412-
procedure TWSThread.AddToHashList(AStation: TBytes; ATemp: Int64; AHash: QWord);
381+
procedure TWSThread.AddToHashList(ABytes: TBytes; AStartP, AEndP: Int64;
382+
ATemp: Int64; AHash: QWord);
413383
var
414384
Index: Integer;
415385
begin
@@ -418,16 +388,16 @@ procedure TWSThread.AddToHashList(AStation: TBytes; ATemp: Int64; AHash: QWord);
418388
begin
419389
if FWSList[Index].FStation = nil then
420390
begin
421-
SetLength(FWSList[Index].FStation, Length(AStation));
422-
Move(AStation[0], FWSList[Index].FStation[0], Length(AStation));
391+
SetLength(FWSList[Index].FStation, AEndP - AStartP);
392+
Move(ABytes[AStartP], FWSList[Index].FStation[0], AEndP - AStartP);
423393
FWSList[Index].FData.FMin := ATemp;
424394
FWSList[Index].FData.FMax := ATemp;
425395
FWSList[Index].FData.FTot := ATemp;
426396
FWSList[Index].FData.FCnt := 1;
427397
FWSList[Index].FData.FHash := AHash;
428398
Break;
429399
end;
430-
if CompareMem(@FWSList[Index].FStation[0], @AStation[0], Length(AStation)) then
400+
if CompareMem(@FWSList[Index].FStation[0], @ABytes[AStartP], AEndP - AStartP) then
431401
begin
432402
FWSList[Index].FData.FMin := min(FWSList[Index].FData.FMin, ATemp);
433403
FWSList[Index].FData.FMax := max(FWSList[Index].FData.FMax, ATemp);
@@ -537,7 +507,7 @@ procedure TWSThreadsWatcher.CreateFinalList;
537507
Min, Max: Double;
538508
Mean: Double;
539509
SL: TStringList;
540-
MS: TMemoryStream;
510+
//MS: TMemoryStream;
541511
begin
542512
SL := TStringList.Create;
543513
try
@@ -557,8 +527,8 @@ procedure TWSThreadsWatcher.CreateFinalList;
557527
Str := Name + '=' + FormatFloat('0.0', Min) + '/' + FormatFloat('0.0', Mean) + '/' + FormatFloat('0.0', Max) + ',';
558528
SL.Add(Str);
559529
end;
560-
SL.EndUpdate;
561530
SL.CustomSort(@Compare);
531+
SL.EndUpdate;
562532
Str := SL.Text;
563533
finally
564534
SL.Free;

utilities/script_builder/Common/scriptbuilder.common.pas

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ procedure TBuilder.BuildCompileScriptBash;
150150
//for entry in FConfig.Entries do
151151
begin
152152
Write(GenerateProgressBar(index+1, FConfig.Entries.Count, 50), lineBreak);
153+
if not FConfig.Entries[index].Active then continue;
153154
if FConfig.Entries[index].Compiler <> cCompilerFPC then continue;
154155
//if FConfig.Entries[index].EntryBinary = cBaselineBinary then continue;
155156
line:= line + 'echo "===== '+ FConfig.Entries[index].Name +' ======"' + LineEnding;
@@ -215,6 +216,7 @@ procedure TBuilder.BuildTestScriptBash;
215216
for index:= 0 to Pred(FConfig.Entries.Count) do
216217
begin
217218
Write(GenerateProgressBar(index+1, FConfig.Entries.Count, 50), lineBreak);
219+
if not FConfig.Entries[index].Active then continue;
218220
//if FConfig.Entries[index].EntryBinary = cBaselineBinary then continue;
219221
line:= line + 'echo "===== '+ FConfig.Entries[index].Name +' ======"' + LineEnding;
220222
tmpStr:= Format('%s%s %s', [
@@ -272,6 +274,7 @@ procedure TBuilder.BuildRunScriptBash;
272274
for index:= 0 to Pred(FConfig.Entries.Count) do
273275
begin
274276
Write(GenerateProgressBar(index+1, FConfig.Entries.Count, 50), lineBreak);
277+
if not FConfig.Entries[index].Active then continue;
275278
if FConfig.Entries[index].EntryBinary = cBaselineBinary then continue;
276279
line:= line + 'echo "===== '+ FConfig.Entries[index].Name +' ======"' + LineEnding;
277280
// Run for SSD

utilities/script_builder/Common/scriptbuilder.data.entries.pas

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ interface
3333
{ TEntry }
3434
TEntry = class(TObject)
3535
private
36+
FActive: Boolean;
3637
FName: String;
3738
FNotes: String;
3839
FCompiler: String;
@@ -54,6 +55,9 @@ TEntry = class(TObject)
5455

5556
destructor Destroy; override;
5657

58+
property Active: Boolean
59+
read FActive
60+
write FActive;
5761
property Name: String
5862
read FName
5963
write FName;
@@ -134,6 +138,7 @@ TEntriesEnumerator = class(TObject)
134138
implementation
135139

136140
const
141+
cJSONActive = 'active';
137142
cJSONName = 'name';
138143
cJSONNotes = 'notes';
139144
cJSONCompiler = 'compiler';
@@ -155,6 +160,7 @@ implementation
155160

156161
constructor TEntry.Create;
157162
begin
163+
FActive:= false;
158164
FName:= '';
159165
FNotes:= '';
160166
FCompiler:= '';
@@ -188,6 +194,7 @@ procedure TEntry.setFromJSONData(const AJSONData: TJSONData);
188194

189195
procedure TEntry.setFromJSONObject(const AJSONObject: TJSONObject);
190196
begin
197+
FActive:= AJSONObject.Get(cJSONActive, FActive);
191198
FName:= AJSONObject.Get(cJSONName, FName);
192199
FNotes:= AJSONObject.Get(cJSONNotes, FNotes);
193200
FCompiler:= AJSONObject.Get(cJSONCompiler, FCompiler);

0 commit comments

Comments
 (0)