Created
December 3, 2025 02:02
-
-
Save nubunto/c28e54d9ae3ad7fc961b302daa88be5b to your computer and use it in GitHub Desktop.
D 1B rows generator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import std.parallelism, std.stdio; | |
| import core.cpuid, core.sync.mutex; | |
| void main(string[] args) { | |
| auto f = File("measurements.txt", "w"); | |
| auto mutex = new shared Mutex(); | |
| scope(exit) f.close(); | |
| writeln("generating measurements"); | |
| const totalRows = 1_000_000_000; | |
| const chunkSize = 5_000_000; | |
| const numChunks = totalRows / chunkSize; | |
| foreach (i; parallel(iota(numChunks))) { | |
| auto ap = appender!(char[]); | |
| ap.reserve(chunkSize * 25); | |
| auto rnd = Xorshift(unpredictableSeed); | |
| foreach(j; iota(chunkSize)) { | |
| auto randomStation = stationNames[uniform(0, stationNames.length, rnd)]; | |
| auto measurement = uniform(-50f, 50f, rnd); | |
| formattedWrite(ap, "%s;%.1f\n", randomStation, measurement); | |
| } | |
| mutex.lock(); | |
| f.rawWrite(ap.data); | |
| mutex.unlock(); | |
| if (i % 10 == 0) { | |
| writefln("chunk %d/%d generated", i, numChunks); | |
| } | |
| } | |
| writeln("done"); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment