Skip to content

Commit 72157bb

Browse files
Merge branch 'main' of github.com:corneliusdavid/1BRC-Delphi into main
# Conflicts: # generator/Delphi/src/generator.dpr
2 parents b9ef1b3 + ab0f831 commit 72157bb

28 files changed

+2632
-267
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
/bin
33
/data/measurements*.txt
44
/profiling
5+
/results
6+
/entries/entries.json
7+
compile_all.*
8+
test_all.*
9+
run_all.*
510

611
# Compiled l10n files: .mo should be ignored
712
*.mo

README.md

Lines changed: 73 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
# 1️⃣🐝🏎️ The One Billion Row Challenge in Object Pascal
2+
<p>
3+
<a href="https://discord.gg/c382VBk"><img src="https://img.shields.io/discord/623794270255579146?label=Delphi Community Discord" alt="Delphi Community" /></a>
4+
<a href="https://discord.gg/3VdxbSFyJP"><img src="https://img.shields.io/discord/570025060312547359?label=Unofficial Free Pacal Discord" alt="Unofficial Free Pacal" /></a>
5+
</p>
26

37
This is the repository that will coordinate the 1 Billion Row Challenge for Object Pascal.
48

@@ -25,7 +29,7 @@ Conakry;31.2
2529
Istanbul;23.0
2630
```
2731

28-
The task is to write an Object Pascal program which reads the file, calculates the min, mean, and max temperature value per weather station, and emits the results on `STDOUT` like this (i.e. sorted alphabetically by station name, and the result values per station in the format `<min>/<mean>/<max>`, rounded to one fractional digit):
32+
The task is to write an Object Pascal program which reads the file, calculates the min, mean, and max temperature value per weather station, and emits the results on `STDOUT` like this (i.e., sorted alphabetically by station name, and the result values per station in the format `<min>/<mean>/<max>`, rounded to one fractional digit towards positive infinity with both `17.01` and `17.05` being rounded to `17.1`, with the decimal separator being a period `.`):
2933

3034
```
3135
{Abha=-23.0/18.0/59.2, Abidjan=-16.2/26.0/67.3, Abéché=-10.0/29.4/69.0, Accra=-10.1/26.4/66.4, Addis Ababa=-23.7/16.0/67.0, Adelaide=-27.8/17.3/58.5, ...}
@@ -43,14 +47,54 @@ When creating your entry, please do as follows:
4347
5. If you need to provide a custom `.gitignore` for something not present in the main one, please do.
4448

4549
This challenge is mainly to allow us to learn something new. This means that copying code from others will be allowed, under these conditions:
46-
1. You can only use pure Object Pascal with no calls to any operating system's `API` or external `C/C++` libraries.
50+
1. You can only use pure Object Pascal with no calls to any operating system's `API` or external `C/C++` libraries. \
51+
**There's been a bit of confusion about this restriction.** \
52+
To clear that out: You can use any package/custom code you want. \
53+
As long as it compiles cross-platform and itself is only pure Object Pascal. \
54+
Anything from the `Jedi Project` or even `mORMmot` ( or anything else ), if it compiles, runs cross-platform it's allowed.
4755
2. The code must have some sort of mention/attribution to the original author, in case you've used someone else's code.
4856
3. It's not a blatant copy just for the sake of submission.
4957
4. It adds something of value, not just a different code formatting.
5058
5. All code should be formatted with the `IDE`'s default formatting tool.
5159

60+
**IMPORTANT** \
61+
This challenge can be entered even if you only have access to the Community Edition of RAD Studio. \
62+
I have a Windows VM, with RAD Studio installed, that will do the necessary cross compilation into my Linux host.
63+
5264
Submit your implementation and become part of the leader board!
5365

66+
## Rounding
67+
68+
Székely Balázs has provided code for rounding towards positive infinity per the original challenge.\
69+
This will be the official way to round the output values:
70+
```pas
71+
function TBaseline.RoundEx(x: Double): Double;
72+
begin
73+
Result := PascalRound(x*10.0)/10.0;
74+
end;
75+
76+
function TBaseline.PascalRound(x: Double): Double;
77+
var
78+
t: Double;
79+
begin
80+
//round towards positive infinity
81+
t := Trunc(x);
82+
if (x < 0.0) and (t - x = 0.5) then
83+
begin
84+
// Do nothing
85+
end
86+
else if Abs(x - t) >= 0.5 then
87+
begin
88+
t := t + Math.Sign(x);
89+
end;
90+
91+
if t = 0.0 then
92+
Result := 0.0
93+
else
94+
Result := t;
95+
end;
96+
```
97+
5498
## Generating the measurements.txt
5599
> **NOTE** \
56100
> We now have both a Lazarus version and a Delphi version of the generator for both 32b and 64b.
@@ -59,30 +103,42 @@ In order to produce the One Billion Rows of text, we are providing the [source c
59103

60104
| Parameter | Description |
61105
|:----------|:------------|
62-
| -h or --help | Writes this help message and exits |
63-
| -v or --version | Writes the version and exits |
64-
| -i or --input-file <filename> | The file containing the Weather Stations |
65-
| -o or --output-file <filename> | The file that will contain the generated lines |
66-
| -n or --line-count <number> | The amount of lines to be generated ( Can use 1_000_000_000 ) |
106+
| **-h** or **--help** | Writes this help message and exits |
107+
| **-v** or **--version** | Writes the version and exits |
108+
| **-i** or **--input-file \<filename\>** | The file containing the Weather Stations |
109+
| **-o** or **--output-file \<filename\>** | The file that will contain the generated lines |
110+
| **-n** or **--line-count \<number\>** | The amount of lines to be generated ( Can use 1_000_000_000 ) |
67111

112+
## Baseline
113+
> **NOTE** \
114+
> This is still a bit in flux, still needing to get the Delphi version done.
115+
116+
In order to verify the official output, we are providing the [source code](./baseline) for the official baseline.
117+
118+
| Parameter | Description |
119+
|:----------|:------------|
120+
| **-h** or **--help** | Writes this help message and exits |
121+
| **-v** or **--version** | Writes the version and exits |
122+
| **-i** or **--input-file \<filename\>** | The file containing the 1 billion rows |
68123

69-
### Verify
124+
## Verify Input File
70125
You can verify the generated `measurements.txt` with a `SHA256` utility:
71126

72127
**Linux**
73-
```sh
128+
```bash
74129
$ sha256sum ./data/measurements.txt
75130
```
76131
**Windows (PowerShell)**
77-
```ps
132+
```powershell
78133
Get-FileHash .\data\measurements.txt -Algorithm SHA256
79134
```
80135
Expected `SHA256` hash:
81136
`ebad17b266ee9f5cb3d118531f197e6f68c9ab988abc5cb9506e6257e1a52ce6`
82137

138+
## Verify Output File
83139
> **NOTE**
84140
>
85-
> I'm still being lazy and I need to do the baseline in order for us to have the same `SHA256` value for an official output.
141+
> We are still waiting for the Delphi version to be completed in order for us to have an official `SHA256` hash for the output.
86142
87143
## Results
88144
These are the results from running all entries into the challenge on my personal computer:
@@ -94,7 +150,8 @@ These are the results from running all entries into the challenge on my personal
94150

95151
| # | Result (m:s.ms): SSD | Result (m:s.ms): HDD | Compiler | Submitter | Notes | Certificates |
96152
|--:|---------------------:|---------------------:|:---------|:--------------|:----------|:-------------|
97-
| 1 | 0:29.212 | 2:2.504 | lazarus-3.0, fpc-3.2.2 | Székely Balázs | Using 16 threads | |
153+
| 1 | 0:29.212 | 2:2.504 | lazarus-3.0, fpc-3.2.2 | Székely Balázs | Using 16 threads | |
154+
| 2 | 15:3.075 | 15:7.630 | lazarus-3.0, fpc-3.2.2 | Iwan Kelaiah | Using 1 thread | |
98155

99156
## Evaluating Results
100157
Each contender is run 10 times in a row for both `SSD` and `HDD` using `hyperfine` for the time taking. \
@@ -112,11 +169,13 @@ _Q: What is the encoding of the measurements.txt file?_\
112169
A: The file is encoded with UTF-8.
113170

114171
_Q: Which operating system is used for evaluation?_\
115-
A: Ubuntu 23.10.
172+
A: Ubuntu 23.10 64b.
116173

117174
## Honour Mentions
118175
I'd like to thank [@paweld](https://github.com/paweld) for taking us from my miserable 20m attempt, to a whopping ~25s, beating the [Python script](https://github.com/gunnarmorling/1brc/blob/main/src/main/python/create_measurements.py) by about 4 and a half minutes.\
119-
I'd like to thank [@mobius](https://github.com/mobius1qwe) for taking the time to provide the Delphi version of the generator.
176+
I'd like to thank [@mobius](https://github.com/mobius1qwe) for taking the time to provide the Delphi version of the generator.\
177+
I'd like to thank [@dtpfl](https://github.com/dtpfl) for his invaluable work on maintaining the `README.md` file up to date with everything.\
178+
I'd like to thank Székely Balázs for providing many patches to make everything compliant with the original challenge.
120179

121180
## Links
122181
The original repository: https://github.com/gunnarmorling/1brc \

0 commit comments

Comments
 (0)