diff --git a/CreateMeasurements3.java b/CreateMeasurements3.java index 9bcc16d..9b8df75 100644 --- a/CreateMeasurements3.java +++ b/CreateMeasurements3.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package dev.morling.onebrc; import java.io.BufferedReader; import java.io.BufferedWriter; @@ -24,7 +23,7 @@ import java.io.StringReader; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.HashSet; -import java.util.concurrent.ThreadLocalRandom; +import java.util.Random; public class CreateMeasurements3 { @@ -32,23 +31,26 @@ public class CreateMeasurements3 { public static final int KEYSET_SIZE = 10_000; public static void main(String[] args) throws Exception { - if (args.length != 1) { - System.out.println("Usage: create_measurements3.sh "); + if (args.length != 3) { + System.out.println("Usage: create_measurements3.sh "); System.exit(1); } + String weatherStationsCsv = args[0]; int size = 0; + int seed = 0; try { - size = Integer.parseInt(args[0]); + size = Integer.parseInt(args[1]); + seed = Integer.parseInt(args[2]); } catch (NumberFormatException e) { - System.out.println("Invalid value for "); - System.out.println("Usage: create_measurements3.sh "); + System.out.println("Invalid value for or "); + System.out.println("Usage: create_measurements3.sh "); System.exit(1); } - final var weatherStations = generateWeatherStations(); + final var rnd = new Random(seed); + final var weatherStations = generateWeatherStations(rnd, weatherStationsCsv); final var start = System.currentTimeMillis(); - final var rnd = ThreadLocalRandom.current(); - try (var out = new BufferedWriter(new FileWriter("measurements3.txt"))) { + try (var out = new BufferedWriter(new FileWriter("measurements.txt"))) { for (int i = 1; i <= size; i++) { var station = weatherStations.get(rnd.nextInt(KEYSET_SIZE)); double temp = rnd.nextGaussian(station.avgTemp, 7.0); @@ -66,11 +68,11 @@ public class CreateMeasurements3 { record WeatherStation(String name, float avgTemp) { } - private static ArrayList generateWeatherStations() throws Exception { + private static ArrayList generateWeatherStations(Random rnd, String weatherStationsCsvPath) throws Exception { // Use a public list of city names and concatenate them all into a long string, // which we'll use as a "source of city name randomness" var bigName = new StringBuilder(1 << 20); - try (var rows = new BufferedReader(new FileReader("data/weather_stations.csv"));) { + try (var rows = new BufferedReader(new FileReader(weatherStationsCsvPath));) { skipComments(rows); while (true) { var row = rows.readLine(); @@ -84,11 +86,10 @@ public class CreateMeasurements3 { final var names = new HashSet(); var minLen = Integer.MAX_VALUE; var maxLen = Integer.MIN_VALUE; - try (var rows = new BufferedReader(new FileReader("data/weather_stations.csv"))) { + try (var rows = new BufferedReader(new FileReader(weatherStationsCsvPath))) { skipComments(rows); final var nameSource = new StringReader(bigName.toString()); final var buf = new char[MAX_NAME_LEN]; - final var rnd = ThreadLocalRandom.current(); final double yOffset = 4; final double factor = 2500; final double xOffset = 0.372;