diff --git a/README.md b/README.md index 19d2124..1ddfb2d 100644 --- a/README.md +++ b/README.md @@ -63,7 +63,7 @@ See [below](#entering-the-challenge) for instructions how to enter the challenge This repository contains two programs: * `dev.morling.onebrc.CreateMeasurements` (invoked via _create\_measurements.sh_): Creates the file _measurements.txt_ in the root directory of this project with a configurable number of random measurement values -* `dev.morling.onebrc.CalculateAverage` (invoked via _calculate\_average.sh_): Calculates the average values for the file _measurements.txt_ +* `dev.morling.onebrc.CalculateAverage` (invoked via _calculate\_average\_baseline.sh_): Calculates the average values for the file _measurements.txt_ Execute the following steps to run the challenge: @@ -133,7 +133,7 @@ To submit your own implementation to 1BRC, follow these steps: * Create a fork of the [onebrc](https://github.com/gunnarmorling/onebrc/) GitHub repository. * Create a copy of _CalculateAverage.java_, named _CalculateAverage\_.java_, e.g. _CalculateAverage\_doloreswilson.java_. * Make that implementation fast. Really fast. -* Create a copy of _calculate_average.sh_, named _calculate\_average\_.sh_, e.g. _calculate\_average\_doloreswilson.sh_. +* Create a copy of _calculate_average_baseline.sh_, named _calculate\_average\_.sh_, e.g. _calculate\_average\_doloreswilson.sh_. * Adjust that script so that it references your implementation class name. If needed, provide any JVM arguments via the `JAVA_OPTS` variable in that script. * OpenJDK 21 is the default. If a custom JDK build is required, include the SDKMAN command `sdk use java [version]` in the launch shell script prior to application start. * (Optional) If you'd like to use native binaries (GraalVM), adjust the _pom.xml_ file so that it builds that binary. diff --git a/calculate_average.sh b/calculate_average_baseline.sh similarity index 100% rename from calculate_average.sh rename to calculate_average_baseline.sh diff --git a/evaluate.sh b/evaluate.sh index 58aea67..8fbc109 100755 --- a/evaluate.sh +++ b/evaluate.sh @@ -25,6 +25,9 @@ java --version mvn clean verify +rm -f measurements.txt +ln -s measurements_1B.txt measurements.txt + for i in {1..5} do ./calculate_average_$1.sh diff --git a/process_output.java b/process_output.java new file mode 100644 index 0000000..4349872 --- /dev/null +++ b/process_output.java @@ -0,0 +1,67 @@ +/* + * 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. + */ + +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +public class process_output { + + public static void main(String... args) throws Exception { + String expectedFile = args[0]; + String actualFile = args[1]; + + String expected = new String(Files.readAllBytes(Paths.get(expectedFile))); + List times = new ArrayList<>(); + + var outputLines = Files.lines(Paths.get(actualFile)) + .collect(Collectors.toList()); + + int matched = 0; + + for (String line : outputLines) { + if (line.contains("Hamburg")) { + if (!line.equals(expected)) { + System.err.println("FAILURE Unexpected output"); + System.err.println(line); + } + else { + matched++; + } + } + else if (line.startsWith("real")) { + times.add(line); + } + } + + if (matched == 5) { + System.out.println("OK Output matched"); + } + else { + System.err.println("FAILURE Output didn't match"); + } + + System.out.println(); + System.out.println(actualFile); + + System.out.println(times.stream() + .map(t -> t.substring(5)) + .map(t -> t.replace("s", "").replace("m", ":")) + .collect(Collectors.joining(System.lineSeparator()))); + } +} diff --git a/src/test/resources/samples/measurements-20.out b/src/test/resources/samples/measurements-20.out new file mode 100644 index 0000000..9bf1fec --- /dev/null +++ b/src/test/resources/samples/measurements-20.out @@ -0,0 +1 @@ +{AbΓ©chΓ©1οΈβƒ£πŸπŸŽοΈ=27.3/27.3/27.3, Almaty1οΈβƒ£πŸπŸŽοΈ=15.3/15.3/15.3, Baghdad1οΈβƒ£πŸπŸŽοΈ=26.0/26.0/26.0, Bangkok1οΈβƒ£πŸπŸŽοΈ=25.6/25.6/25.6, Berlin1οΈβƒ£πŸπŸŽοΈ=-0.3/-0.3/-0.3, Birao1οΈβƒ£πŸπŸŽοΈ=33.5/33.5/33.5, Canberra1οΈβƒ£πŸπŸŽοΈ=5.2/5.2/5.2, Chittagong1οΈβƒ£πŸπŸŽοΈ=12.6/12.6/12.6, Da Nang1οΈβƒ£πŸπŸŽοΈ=33.7/33.7/33.7, Edinburgh1οΈβƒ£πŸπŸŽοΈ=19.8/19.8/19.8, Irkutsk1οΈβƒ£πŸπŸŽοΈ=9.9/9.9/9.9, Lhasa1οΈβƒ£πŸπŸŽοΈ=13.4/13.4/13.4, Lyon1οΈβƒ£πŸπŸŽοΈ=1.8/1.8/1.8, Mogadishu1οΈβƒ£πŸπŸŽοΈ=11.5/11.5/11.5, Nashville1οΈβƒ£πŸπŸŽοΈ=-4.9/-4.9/-4.9, Odesa1οΈβƒ£πŸπŸŽοΈ=6.5/6.5/6.5, Parakou1οΈβƒ£πŸπŸŽοΈ=36.3/36.3/36.3, Tamanrasset1οΈβƒ£πŸπŸŽοΈ=17.9/17.9/17.9, Tirana1οΈβƒ£πŸπŸŽοΈ=27.7/27.7/27.7, Xi'an1οΈβƒ£πŸπŸŽοΈ=17.5/17.5/17.5} diff --git a/src/test/resources/samples/measurements-20.txt b/src/test/resources/samples/measurements-20.txt new file mode 100644 index 0000000..19bdfd5 --- /dev/null +++ b/src/test/resources/samples/measurements-20.txt @@ -0,0 +1,20 @@ +Odesa1οΈβƒ£πŸπŸŽοΈ;6.5 +Canberra1οΈβƒ£πŸπŸŽοΈ;5.2 +Lhasa1οΈβƒ£πŸπŸŽοΈ;13.4 +Edinburgh1οΈβƒ£πŸπŸŽοΈ;19.8 +Da Nang1οΈβƒ£πŸπŸŽοΈ;33.7 +Xi'an1οΈβƒ£πŸπŸŽοΈ;17.5 +Berlin1οΈβƒ£πŸπŸŽοΈ;-0.3 +Tamanrasset1οΈβƒ£πŸπŸŽοΈ;17.9 +AbΓ©chΓ©1οΈβƒ£πŸπŸŽοΈ;27.3 +Baghdad1οΈβƒ£πŸπŸŽοΈ;26.0 +Lyon1οΈβƒ£πŸπŸŽοΈ;1.8 +Mogadishu1οΈβƒ£πŸπŸŽοΈ;11.5 +Bangkok1οΈβƒ£πŸπŸŽοΈ;25.6 +Irkutsk1οΈβƒ£πŸπŸŽοΈ;9.9 +Parakou1οΈβƒ£πŸπŸŽοΈ;36.3 +Almaty1οΈβƒ£πŸπŸŽοΈ;15.3 +Birao1οΈβƒ£πŸπŸŽοΈ;33.5 +Chittagong1οΈβƒ£πŸπŸŽοΈ;12.6 +Tirana1οΈβƒ£πŸπŸŽοΈ;27.7 +Nashville1οΈβƒ£πŸπŸŽοΈ;-4.9 diff --git a/src/test/resources/samples/measurements-3.out b/src/test/resources/samples/measurements-3.out new file mode 100644 index 0000000..5a9fc91 --- /dev/null +++ b/src/test/resources/samples/measurements-3.out @@ -0,0 +1 @@ +{Bosaso=-15.0/1.3/20.5, Petropavlovsk-Kamchatsky=-9.5/0.0/9.5} diff --git a/src/test/resources/samples/measurements-3.txt b/src/test/resources/samples/measurements-3.txt new file mode 100644 index 0000000..21d541d --- /dev/null +++ b/src/test/resources/samples/measurements-3.txt @@ -0,0 +1,6 @@ +Bosaso;5.0 +Bosaso;20.0 +Bosaso;-5.0 +Bosaso;-15.0 +Petropavlovsk-Kamchatsky;9.5 +Petropavlovsk-Kamchatsky;-9.5 diff --git a/src/test/resources/samples/measurements-boundaries.out b/src/test/resources/samples/measurements-boundaries.out new file mode 100644 index 0000000..d34baba --- /dev/null +++ b/src/test/resources/samples/measurements-boundaries.out @@ -0,0 +1 @@ +{Bosaso=-99.9/-99.9/-99.9, Petropavlovsk-Kamchatsky=99.9/99.9/99.9} diff --git a/src/test/resources/samples/measurements-boundaries.txt b/src/test/resources/samples/measurements-boundaries.txt new file mode 100644 index 0000000..89bd952 --- /dev/null +++ b/src/test/resources/samples/measurements-boundaries.txt @@ -0,0 +1,2 @@ +Bosaso;-99.9 +Petropavlovsk-Kamchatsky;99.9 diff --git a/test.sh b/test.sh index 8119e70..16308ba 100755 --- a/test.sh +++ b/test.sh @@ -31,6 +31,6 @@ do rm -f measurements.txt ln -s $sample measurements.txt - diff <(./calculate_average.sh) ${sample%.txt}.out + diff <("./calculate_average_$1.sh") ${sample%.txt}.out done rm measurements.txt