Documentation
¶
Overview ¶
Example 06_csv_import — an interchange round-trip benchmark for the edge-list serialisers: generate a seeded follower graph as CSV in memory, parse it back with csv.ReadIntoCtx, then re-serialise the resulting graph as CSV with csv.WriteCtx and as newline-delimited JSON (JSON Lines) with jsonl.WriteCtx, measuring each leg.
It exists to exercise the io/csv and io/jsonl packages on a realistic, scale-parametrised dataset and to report the evidence that matters for an interchange subject — parse and serialise throughput (rows/s, MiB/s), bytes in and out for each format, and live heap — while pinning a deterministic data shape with a regression test.
Model ¶
The dataset is a directed follower graph: handles follow other handles. Each node is a 24-char hex id; each edge is one CSV row of
src,dst,weight
where weight is a small integer in [1, weightMax] (think interaction strength). Every user is given a random out-degree in [followsMin, followsMax] to distinct other users — no self-loops and no duplicate (src,dst) pairs — so the graph is simple and the row count is exactly the edge count. This matters for the round-trip invariant: a simple directed graph re-serialises to exactly as many CSV rows as were ingested, with none collapsed by parallel-edge deduplication.
Pipeline ¶
- Generate a CSV edge list from the seeded RNG into an in-memory buffer (this is the "bytes in").
- Parse it back with csv.ReadIntoCtx, genuinely exercising the CSV reader (this is the parse leg).
- Serialise the parsed graph to an in-memory buffer with csv.WriteCtx (the CSV serialise leg; "bytes out, csv").
- Serialise the same graph with jsonl.WriteCtx (the JSON Lines serialise leg; "bytes out, jsonl"). JSON Lines emits one record per node followed by one record per edge, so its line count is nodes + edges.
- Re-parse the written CSV with csv.ReadIntoCtx and confirm the edge count is unchanged — the round-trip invariant.
At the default scale the example does NOT dump the CSV or JSON Lines to stdout — that would be large and would read as non-deterministic. The round-trip output is written to in-memory buffers; only the deterministic facts and the volatile "# " telemetry are printed, plus a few sample lines of each format so a reader can see the shape.
Scale ¶
Run with no flags, the example builds a small deterministic default (1000 users, 3-6 follows each) that stays well under the short-test budget. Every dimension is a flag, so the same binary scales up to a size where the serialisers' throughput is actually observable:
go run ./examples/06_csv_import -nodes 1000000 -follows-max 12 -seed 7
The deterministic data shape is reproducible for a fixed -seed; only the telemetry (lines prefixed with "# ") varies between runs and machines.