collab/1brc

the one billion row challenge

git clone https://git.julia.blue/collab/1brc

Julia Ryaninitial1e4a890

julia-baseline
2.9 KiB72 linesraw
1diff --git a/CreateMeasurements.java b/CreateMeasurements.java
2index 94b3ff2..1b75349 100644
3--- a/CreateMeasurements.java
4+++ b/CreateMeasurements.java
5@@ -13,21 +13,21 @@
6  *  See the License for the specific language governing permissions and
7  *  limitations under the License.
8  */
9-package dev.morling.onebrc;
10+// package dev.morling.onebrc;
11 
12 import java.io.BufferedWriter;
13 import java.nio.file.Files;
14 import java.nio.file.Path;
15 import java.util.List;
16-import java.util.concurrent.ThreadLocalRandom;
17+import java.util.Random;
18 
19 public class CreateMeasurements {
20 
21     private static final Path MEASUREMENT_FILE = Path.of("./measurements.txt");
22 
23     private record WeatherStation(String id, double meanTemperature) {
24-        double measurement() {
25-            double m = ThreadLocalRandom.current().nextGaussian(meanTemperature, 10);
26+        double measurement(Random rnd) {
27+            double m = rnd.nextGaussian(meanTemperature, 10);
28             return Math.round(m * 10.0) / 10.0;
29         }
30     }
31@@ -35,18 +35,20 @@ public class CreateMeasurements {
32     public static void main(String[] args) throws Exception {
33         long start = System.currentTimeMillis();
34 
35-        if (args.length != 1) {
36-            System.out.println("Usage: create_measurements.sh <number of records to create>");
37+        if (args.length != 2) {
38+            System.out.println("Usage: create_measurements.sh <number of records to create> <seed>");
39             System.exit(1);
40         }
41 
42         int size = 0;
43+        int seed = 0;
44         try {
45             size = Integer.parseInt(args[0]);
46+            seed = Integer.parseInt(args[1]);
47         }
48         catch (NumberFormatException e) {
49-            System.out.println("Invalid value for <number of records to create>");
50-            System.out.println("Usage: CreateMeasurements <number of records to create>");
51+            System.out.println("Invalid value for <number of records to create> or <seed>");
52+            System.out.println("Usage: CreateMeasurements <number of records to create> <seed>");
53             System.exit(1);
54         }
55 
56@@ -490,13 +492,14 @@ public class CreateMeasurements {
57                 new WeatherStation("Zürich", 9.3));
58 
59         try (BufferedWriter bw = Files.newBufferedWriter(MEASUREMENT_FILE)) {
60+            Random rnd = new Random(seed);
61             for (int i = 0; i < size; i++) {
62                 if (i > 0 && i % 50_000_000 == 0) {
63                     System.out.printf("Wrote %,d measurements in %s ms%n", i, System.currentTimeMillis() - start);
64                 }
65-                WeatherStation station = stations.get(ThreadLocalRandom.current().nextInt(stations.size()));
66+                WeatherStation station = stations.get(rnd.nextInt(stations.size()));
67                 bw.write(station.id());
68-                bw.write(";" + station.measurement());
69+                bw.write(";" + station.measurement(rnd));
70                 bw.write('\n');
71             }
72         }