Skip to content

Commit 2e26992

Browse files
Go implementation by AlexanderYastrebov
This is a proof-of-concept to demonstrate non-java submission. It requires Docker with BuildKit plugin to build and export binary. Updates * #67 * #253
1 parent 3127962 commit 2e26992

9 files changed

+491
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,4 @@ out/
4646
/measurements*.txt
4747
/*.out
4848
out_expected.txt
49+
/*-timing.json
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
#
3+
# Copyright 2023 The original authors
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
INPUT=${1:-"measurements.txt"}
19+
20+
target/AlexanderYastrebov/1brc "$INPUT"

github_users.txt

+1
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,4 @@ yavuztas;Yavuz Tas
4949
yehwankim23;김예환 Ye-Hwan Kim (Sam)
5050
hundredwatt;Jason Nochlin
5151
gnmathur;Gaurav Mathur
52+
AlexanderYastrebov;Alexander Yastrebov

prepare_AlexanderYastrebov.sh

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
#
3+
# Copyright 2023 The original authors
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
DOCKER_BUILDKIT=1 docker build -o target/AlexanderYastrebov src/main/go/AlexanderYastrebov
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#
2+
# Copyright 2023 The original authors
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
17+
FROM golang AS build-stage
18+
COPY . src/
19+
RUN cd src && go build .
20+
21+
FROM scratch AS export-stage
22+
COPY --from=build-stage /go/src/1brc /
+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# 1brc in go
2+
3+
It uses Docker with BuildKit plugin to build and [export binary](https://docs.docker.com/engine/reference/commandline/build/#output) binary,
4+
see [prepare_AlexanderYastrebov.sh](../../../../prepare_AlexanderYastrebov.sh)
5+
and [calculate_average_AlexanderYastrebov.sh](../../../../calculate_average_AlexanderYastrebov.sh).
6+
7+
Demo:
8+
```sh
9+
$ ./test.sh AlexanderYastrebov
10+
[+] Building 0.2s (9/9) FINISHED
11+
=> [internal] load .dockerignore 0.0s
12+
=> => transferring context: 2B 0.0s
13+
=> [internal] load build definition from Dockerfile 0.0s
14+
=> => transferring dockerfile: 172B 0.0s
15+
=> [internal] load metadata for docker.io/library/golang:latest 0.0s
16+
=> [internal] load build context 0.0s
17+
=> => transferring context: 145B 0.0s
18+
=> [build-stage 1/3] FROM docker.io/library/golang 0.0s
19+
=> CACHED [build-stage 2/3] COPY . src/ 0.0s
20+
=> CACHED [build-stage 3/3] RUN cd src && go build . 0.0s
21+
=> CACHED [export-stage 1/1] COPY --from=build-stage /go/src/1brc / 0.0s
22+
=> exporting to client directory 0.1s
23+
=> => copying files 2.03MB 0.0s
24+
Validating calculate_average_AlexanderYastrebov.sh -- src/test/resources/samples/measurements-10000-unique-keys.txt
25+
Validating calculate_average_AlexanderYastrebov.sh -- src/test/resources/samples/measurements-10.txt
26+
Validating calculate_average_AlexanderYastrebov.sh -- src/test/resources/samples/measurements-1.txt
27+
Validating calculate_average_AlexanderYastrebov.sh -- src/test/resources/samples/measurements-20.txt
28+
Validating calculate_average_AlexanderYastrebov.sh -- src/test/resources/samples/measurements-2.txt
29+
Validating calculate_average_AlexanderYastrebov.sh -- src/test/resources/samples/measurements-3.txt
30+
Validating calculate_average_AlexanderYastrebov.sh -- src/test/resources/samples/measurements-boundaries.txt
31+
Validating calculate_average_AlexanderYastrebov.sh -- src/test/resources/samples/measurements-complex-utf8.txt
32+
Validating calculate_average_AlexanderYastrebov.sh -- src/test/resources/samples/measurements-dot.txt
33+
Validating calculate_average_AlexanderYastrebov.sh -- src/test/resources/samples/measurements-shortest.txt
34+
Validating calculate_average_AlexanderYastrebov.sh -- src/test/resources/samples/measurements-short.txt
35+
36+
# Run once to setup the benchmark
37+
# ./create_measurements.sh 1000000000
38+
# mv measurements.txt measurements_1B.txt
39+
# ln -s measurements_1B.txt measurements.txt
40+
# ./calculate_average_baseline.sh > out_expected.txt
41+
42+
$ wc -l measurements_1B.txt
43+
1000000000 measurements_1B.txt
44+
45+
$ ./evaluate2.sh AlexanderYastrebov royvanrijn
46+
... 0.0s
47+
Benchmark 1: ./calculate_average_AlexanderYastrebov.sh 2>&1
48+
Time (mean ± σ): 16.786 s ± 0.545 s [User: 56.030 s, System: 10.068 s]
49+
Range (min … max): 15.918 s … 17.309 s 5 runs
50+
...
51+
Benchmark 1: ./calculate_average_royvanrijn.sh 2>&1
52+
Time (mean ± σ): 16.731 s ± 0.190 s [User: 56.485 s, System: 10.279 s]
53+
Range (min … max): 16.490 s … 16.951 s 5 runs
54+
55+
Summary
56+
AlexanderYastrebov: trimmed mean 16.901712789513336, raw times 16.69836470718,17.30911065018,16.83413600418,15.91787706218,17.17263765718
57+
royvanrijn: trimmed mean 16.738037123633333, raw times 16.4900939703,16.9513459953,16.5794539913,16.8297746273,16.8048827523
58+
```

0 commit comments

Comments
 (0)