Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Go implementation by AlexanderYastrebov #298

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@ out/
/measurements*.txt
/*.out
out_expected.txt
/*-timing.json
20 changes: 20 additions & 0 deletions calculate_average_AlexanderYastrebov.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash
#
# Copyright 2023 The original authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

INPUT=${1:-"measurements.txt"}

target/AlexanderYastrebov/1brc "$INPUT"
1 change: 1 addition & 0 deletions github_users.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,4 @@ vemana;Subrahmanyam
jincongho;Jin Cong Ho
yonatang;Yonatan Graber
adriacabeza;Adrià Cabeza
AlexanderYastrebov;Alexander Yastrebov
18 changes: 18 additions & 0 deletions prepare_AlexanderYastrebov.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash
#
# Copyright 2023 The original authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

DOCKER_BUILDKIT=1 docker build -o target/AlexanderYastrebov src/main/go/AlexanderYastrebov
22 changes: 22 additions & 0 deletions src/main/go/AlexanderYastrebov/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#
# Copyright 2023 The original authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

FROM golang AS build-stage
COPY . src/
RUN cd src && go build .

FROM scratch AS export-stage
COPY --from=build-stage /go/src/1brc /
58 changes: 58 additions & 0 deletions src/main/go/AlexanderYastrebov/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# 1brc in go

It uses Docker with BuildKit plugin to build and [export binary](https://docs.docker.com/engine/reference/commandline/build/#output) binary,
see [prepare_AlexanderYastrebov.sh](../../../../prepare_AlexanderYastrebov.sh)
and [calculate_average_AlexanderYastrebov.sh](../../../../calculate_average_AlexanderYastrebov.sh).

Demo:
```sh
$ ./test.sh AlexanderYastrebov
[+] Building 0.2s (9/9) FINISHED
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 172B 0.0s
=> [internal] load metadata for docker.io/library/golang:latest 0.0s
=> [internal] load build context 0.0s
=> => transferring context: 145B 0.0s
=> [build-stage 1/3] FROM docker.io/library/golang 0.0s
=> CACHED [build-stage 2/3] COPY . src/ 0.0s
=> CACHED [build-stage 3/3] RUN cd src && go build . 0.0s
=> CACHED [export-stage 1/1] COPY --from=build-stage /go/src/1brc / 0.0s
=> exporting to client directory 0.1s
=> => copying files 2.03MB 0.0s
Validating calculate_average_AlexanderYastrebov.sh -- src/test/resources/samples/measurements-10000-unique-keys.txt
Validating calculate_average_AlexanderYastrebov.sh -- src/test/resources/samples/measurements-10.txt
Validating calculate_average_AlexanderYastrebov.sh -- src/test/resources/samples/measurements-1.txt
Validating calculate_average_AlexanderYastrebov.sh -- src/test/resources/samples/measurements-20.txt
Validating calculate_average_AlexanderYastrebov.sh -- src/test/resources/samples/measurements-2.txt
Validating calculate_average_AlexanderYastrebov.sh -- src/test/resources/samples/measurements-3.txt
Validating calculate_average_AlexanderYastrebov.sh -- src/test/resources/samples/measurements-boundaries.txt
Validating calculate_average_AlexanderYastrebov.sh -- src/test/resources/samples/measurements-complex-utf8.txt
Validating calculate_average_AlexanderYastrebov.sh -- src/test/resources/samples/measurements-dot.txt
Validating calculate_average_AlexanderYastrebov.sh -- src/test/resources/samples/measurements-shortest.txt
Validating calculate_average_AlexanderYastrebov.sh -- src/test/resources/samples/measurements-short.txt

# Run once to setup the benchmark
# ./create_measurements.sh 1000000000
# mv measurements.txt measurements_1B.txt
# ln -s measurements_1B.txt measurements.txt
# ./calculate_average_baseline.sh > out_expected.txt

$ wc -l measurements_1B.txt
1000000000 measurements_1B.txt

$ ./evaluate2.sh AlexanderYastrebov royvanrijn
... 0.0s
Benchmark 1: ./calculate_average_AlexanderYastrebov.sh 2>&1
Time (mean ± σ): 16.786 s ± 0.545 s [User: 56.030 s, System: 10.068 s]
Range (min … max): 15.918 s … 17.309 s 5 runs
...
Benchmark 1: ./calculate_average_royvanrijn.sh 2>&1
Time (mean ± σ): 16.731 s ± 0.190 s [User: 56.485 s, System: 10.279 s]
Range (min … max): 16.490 s … 16.951 s 5 runs

Summary
AlexanderYastrebov: trimmed mean 16.901712789513336, raw times 16.69836470718,17.30911065018,16.83413600418,15.91787706218,17.17263765718
royvanrijn: trimmed mean 16.738037123633333, raw times 16.4900939703,16.9513459953,16.5794539913,16.8297746273,16.8048827523
```
Loading