diff --git a/README.md b/README.md index 1ddfb2d..93ea8e1 100644 --- a/README.md +++ b/README.md @@ -38,19 +38,20 @@ Submit your implementation by Jan 31 2024 and become part of the leaderboard! | # | Result (m:s.ms) | Implementation | JDK | Submitter | |---|-----------------|--------------------|-----|---------------| | 1.| 00:14.848| [link](https://github.com/gunnarmorling/1brc/blob/main/src/main/java/dev/morling/onebrc/CalculateAverage_spullara.java)| 21.0.1-graalce| [Sam Pullara](https://github.com/spullara)| -| 2.| 00:18.865| [link](https://github.com/gunnarmorling/1brc/blob/main/src/main/java/dev/morling/onebrc/CalculateAverage_palmr.java)| 21.0.1-open| [Nick Palmer](https://github.com/palmr)| -| 3.| 00:21.853| [link](https://github.com/gunnarmorling/1brc/blob/main/src/main/java/dev/morling/onebrc/CalculateAverage_filiphr.java)| 21.0.1-graal| [Filip Hrisafov](https://github.com/filiphr)| -| 4.| 00:23.366| [link](https://github.com/gunnarmorling/1brc/pull/5/)| 21.0.1-open | [Roy van Rijn](https://github.com/royvanrijn)| -| 5.| 00:38.106| [link](https://github.com/gunnarmorling/1brc/blob/main/src/main/java/dev/morling/onebrc/CalculateAverage_seijikun.java)| 21.0.1-open | [Markus Ebner](https://github.com/seijikun)| -| 6.| 00:38.510| [link](https://github.com/gunnarmorling/1brc/blob/main/src/main/java/dev/morling/onebrc/CalculateAverage_bjhara.java)| 21.0.1-open | [Hampus Ram](https://github.com/bjhara)| -| 7.| 00:38.819| [link](https://github.com/gunnarmorling/1brc/blob/main/src/main/java/dev/morling/onebrc/CalculateAverage_richardstartin.java)| 21.0.1-open | [Richard Startin](https://github.com/richardstartin)| -| 8.| 00:50.547| [link](https://github.com/gunnarmorling/1brc/blob/main/src/main/java/dev/morling/onebrc/CalculateAverage_padreati.java)| 21.0.1-open | [Aurelian Tutuianu](https://github.com/padreati)| -| 9.| 00:53.679| [link](https://github.com/gunnarmorling/1brc/blob/main/src/main/java/dev/morling/onebrc/CalculateAverage_criccomini.java)| 21.0.1-open | [Chris Riccomini](https://github.com/criccomini)| -|10.| 00:57.141| [link](https://github.com/gunnarmorling/1brc/blob/main/src/main/java/dev/morling/onebrc/CalculateAverage_truelive.java)| 21.0.1-open | [Roman Schweitzer](https://github.com/truelive)| -|11.| 02:00.101| [link](https://github.com/gunnarmorling/1brc/blob/main/src/main/java/dev/morling/onebrc/CalculateAverage_khmarbaise.java)| 21.0.1-open | [khmarbaise](https://github.com/khmarbaise)| -|12.| 02:08.315| [link](https://github.com/gunnarmorling/1brc/blob/main/src/main/java/dev/morling/onebrc/CalculateAverage_itaske.java)| 21.0.1-open | [itaske](https://github.com/itaske)| -|13.| 02:08.650| [link](https://github.com/gunnarmorling/1brc/blob/main/src/main/java/dev/morling/onebrc/CalculateAverage_kuduwa_keshavram.java)| 21.0.1-open | [Kuduwa Keshavram](https://github.com/kuduwa_keshavram)| -|14.| 04:13.449| [link](https://github.com/gunnarmorling/onebrc/blob/main/src/main/java/dev/morling/onebrc/CalculateAverage.java) (baseline)| 21.0.1-open | [Gunnar Morling](https://github.com/gunnarmorling)| +| 2.| 00:17.905| [link](https://github.com/gunnarmorling/1brc/blob/main/src/main/java/dev/morling/onebrc/CalculateAverage_lawrey.java)| 21.0.1-open| [Peter Lawrey](https://github.com/peter-lawrey)| +| 3.| 00:18.865| [link](https://github.com/gunnarmorling/1brc/blob/main/src/main/java/dev/morling/onebrc/CalculateAverage_palmr.java)| 21.0.1-open| [Nick Palmer](https://github.com/palmr)| +| 4.| 00:21.853| [link](https://github.com/gunnarmorling/1brc/blob/main/src/main/java/dev/morling/onebrc/CalculateAverage_filiphr.java)| 21.0.1-graal| [Filip Hrisafov](https://github.com/filiphr)| +| 5.| 00:23.260| [link](https://github.com/gunnarmorling/1brc/blob/main/src/main/java/dev/morling/onebrc/CalculateAverage_richardstartin.java)| 21.0.1-open | [Richard Startin](https://github.com/richardstartin)| +| 6.| 00:23.366| [link](https://github.com/gunnarmorling/1brc/pull/5/)| 21.0.1-open | [Roy van Rijn](https://github.com/royvanrijn)| +| 7.| 00:38.106| [link](https://github.com/gunnarmorling/1brc/blob/main/src/main/java/dev/morling/onebrc/CalculateAverage_seijikun.java)| 21.0.1-open | [Markus Ebner](https://github.com/seijikun)| +| 8.| 00:38.510| [link](https://github.com/gunnarmorling/1brc/blob/main/src/main/java/dev/morling/onebrc/CalculateAverage_bjhara.java)| 21.0.1-open | [Hampus Ram](https://github.com/bjhara)| +| 9.| 00:50.547| [link](https://github.com/gunnarmorling/1brc/blob/main/src/main/java/dev/morling/onebrc/CalculateAverage_padreati.java)| 21.0.1-open | [Aurelian Tutuianu](https://github.com/padreati)| +|10.| 00:53.679| [link](https://github.com/gunnarmorling/1brc/blob/main/src/main/java/dev/morling/onebrc/CalculateAverage_criccomini.java)| 21.0.1-open | [Chris Riccomini](https://github.com/criccomini)| +|11.| 00:57.141| [link](https://github.com/gunnarmorling/1brc/blob/main/src/main/java/dev/morling/onebrc/CalculateAverage_truelive.java)| 21.0.1-open | [Roman Schweitzer](https://github.com/truelive)| +|12.| 02:00.101| [link](https://github.com/gunnarmorling/1brc/blob/main/src/main/java/dev/morling/onebrc/CalculateAverage_khmarbaise.java)| 21.0.1-open | [khmarbaise](https://github.com/khmarbaise)| +|13.| 02:08.315| [link](https://github.com/gunnarmorling/1brc/blob/main/src/main/java/dev/morling/onebrc/CalculateAverage_itaske.java)| 21.0.1-open | [itaske](https://github.com/itaske)| +|14.| 02:08.650| [link](https://github.com/gunnarmorling/1brc/blob/main/src/main/java/dev/morling/onebrc/CalculateAverage_kuduwa_keshavram.java)| 21.0.1-open | [Kuduwa Keshavram](https://github.com/kuduwa_keshavram)| +|15.| 04:13.449| [link](https://github.com/gunnarmorling/onebrc/blob/main/src/main/java/dev/morling/onebrc/CalculateAverage.java) (baseline)| 21.0.1-open | [Gunnar Morling](https://github.com/gunnarmorling)| See [below](#entering-the-challenge) for instructions how to enter the challenge with your own implementation. diff --git a/pom.xml b/pom.xml index 5528c9e..477a56e 100644 --- a/pom.xml +++ b/pom.xml @@ -185,6 +185,7 @@ **/.dontdelete **/measurements*.txt **/measurements*.out + out_expected.txt diff --git a/src/main/java/dev/morling/onebrc/CalculateAverage_lawrey.java b/src/main/java/dev/morling/onebrc/CalculateAverage_lawrey.java index 9af272b..00242fc 100644 --- a/src/main/java/dev/morling/onebrc/CalculateAverage_lawrey.java +++ b/src/main/java/dev/morling/onebrc/CalculateAverage_lawrey.java @@ -159,7 +159,8 @@ public class CalculateAverage_lawrey { m.sample(temp / 10.0); } - } catch (IOException ioe) { + } + catch (IOException ioe) { throw new RuntimeException(ioe); } return map; @@ -169,8 +170,7 @@ public class CalculateAverage_lawrey { private static int readTemperatureFromBuffer(MappedByteBuffer mbb) { int temp = 0; boolean negative = false; - outer: - while (mbb.remaining() > 0) { + outer: while (mbb.remaining() > 0) { byte b = mbb.get(); switch (b) { case '-': diff --git a/src/main/java/dev/morling/onebrc/CalculateAverage_richardstartin.java b/src/main/java/dev/morling/onebrc/CalculateAverage_richardstartin.java index 911ecf9..0d5d2fa 100644 --- a/src/main/java/dev/morling/onebrc/CalculateAverage_richardstartin.java +++ b/src/main/java/dev/morling/onebrc/CalculateAverage_richardstartin.java @@ -87,8 +87,7 @@ public class CalculateAverage_richardstartin { private final Table table = new Table(nextBaseIndex()); - private static final AtomicIntegerFieldUpdater BASE_INDEX_UPDATER = - AtomicIntegerFieldUpdater.newUpdater(Dictionary.class, "baseIndex"); + private static final AtomicIntegerFieldUpdater BASE_INDEX_UPDATER = AtomicIntegerFieldUpdater.newUpdater(Dictionary.class, "baseIndex"); volatile int baseIndex; private void forEach(Table table, IndexedStringConsumer consumer) { @@ -120,13 +119,15 @@ public class CalculateAverage_richardstartin { if (storedKey == null) { if (row.keys.compareAndSet(c, null, slice)) { return table.index(rowIndex, c); - } else { + } + else { storedKey = row.keys.get(c); if (slice.equals(storedKey)) { return table.index(rowIndex, c); } } - } else if (slice.equals(storedKey)) { + } + else if (slice.equals(storedKey)) { return table.index(rowIndex, c); } } @@ -141,8 +142,7 @@ public class CalculateAverage_richardstartin { private static final class Row { - private static final AtomicReferenceFieldUpdater - NEXT_TABLE_UPDATER = AtomicReferenceFieldUpdater.newUpdater(Row.class, Table.class, "next"); + private static final AtomicReferenceFieldUpdater NEXT_TABLE_UPDATER = AtomicReferenceFieldUpdater.newUpdater(Row.class, Table.class, "next"); private final AtomicReferenceArray keys = new AtomicReferenceArray<>(CELLS); volatile Table next; @@ -152,7 +152,8 @@ public class CalculateAverage_richardstartin { Table newTable = new Table(baseIndexSupplier.getAsInt()); if (NEXT_TABLE_UPDATER.compareAndSet(this, null, newTable)) { next = newTable; - } else { + } + else { next = this.next; } } @@ -180,14 +181,16 @@ public class CalculateAverage_richardstartin { private static long compilePattern(long repeat) { return 0x101010101010101L * repeat; } + private static long compilePattern(char delimiter) { - return compilePattern (delimiter & 0xFFL); + return compilePattern(delimiter & 0xFFL); } + private static long compilePattern(byte delimiter) { return compilePattern(delimiter & 0xFFL); } - private static final long NEW_LINE = compilePattern((byte)'\n'); + private static final long NEW_LINE = compilePattern((byte) '\n'); private static final long DELIMITER = compilePattern(';'); private static int firstInstance(long word, long pattern) { @@ -311,11 +314,12 @@ public class CalculateAverage_richardstartin { for (int i = 0; i < contribution.length; i++) { if (aggregate[i] == null) { aggregate[i] = contribution[i]; - } else if (contribution[i] != null) { + } + else if (contribution[i] != null) { double[] to = aggregate[i]; double[] from = contribution[i]; // todo won't vectorise - consider separating aggregates into distinct regions and apply - // loop fission (if this shows up in the profile) + // loop fission (if this shows up in the profile) for (int j = 0; j < to.length; j += 4) { to[j] += from[j]; to[j + 1] = Math.min(to[j + 1], from[j + 1]); @@ -334,7 +338,8 @@ public class CalculateAverage_richardstartin { var slice = slices.get(min); computeSlice(slice, pages); return pages; - } else { + } + else { int mid = (min + max) / 2; var low = new AggregationTask(dictionary, slices, min, mid); var high = new AggregationTask(dictionary, slices, mid + 1, max); @@ -349,7 +354,7 @@ public class CalculateAverage_richardstartin { public static void main(String[] args) throws IOException { int maxChunkSize = 250 << 20; // 250MiB try (var raf = new RandomAccessFile(FILE, "r"); - var channel = raf.getChannel()) { + var channel = raf.getChannel()) { long size = channel.size(); // make as few mmap calls as possible subject to the 2GiB limit per buffer List rawBuffers = new ArrayList<>();