Group-by and join (db-benchmark)

Results

Each run of the full benchmark leaves a JSON file in results/dbbench/, with the machine, the versions and, for each engine and question, three timings. The tables below are a Polars query over those files (run is when it started, in UTC), as in the other benchmark chapters: two rounds of unnest and unpivot give one row per engine and question, and list.min keeps the best of the timed runs.

let index = @["run", "machine", "cpu", "nanuq", "rows"]

proc timings(path: string): DataFrame =
  readJson(path)
    .select(
      col.timestamp.str.slice(0, 16).alias("run"),
      col.label.alias("machine"),
      col.system.struct.field("cpu"),
      col.versions.struct.field("nanuqWrapper").alias("nanuq"),
      col.params.struct.field("rows"),
      col.timings)
    .unnest("timings")
    .unpivot(index = index, variableName = "engine", valueName = "questions")
    .unnest("questions")
    .unpivot(index = index & "engine", variableName = "question", valueName = "seconds")

let times = concat(sorted(toSeq(walkFiles("../results/dbbench/*.json"))).mapIt(timings(it)),
                   how = ConcatMethod.Vertical)
  .withColumns(col.seconds.list.min)
nbShow times.head(3)
shape: (3, 8)
runmachinecpunanuqrowsenginequestionseconds
strstrstrstri64strstrf64
"2026-11-02T14:10""claude-sandbox""Intel(R) Xeon(R) Processor @ 2โ€ฆ"0.6.0"10000000"nanuq in-memory""g1"0.550306
"2026-11-02T14:10""claude-sandbox""Intel(R) Xeon(R) Processor @ 2โ€ฆ"0.6.0"10000000"python in-memory""g1"0.579615
"2026-11-02T14:10""claude-sandbox""Intel(R) Xeon(R) Processor @ 2โ€ฆ"0.6.0"10000000"python streaming""g1"0.453072

The total time of each run, one column per engine:

nbShow times
  .groupBy(index & "engine", maintainOrder = true)
  .agg(col.seconds.sum.round(2))
  .pivot(on = "engine", index = index, values = "seconds", sortColumns = true)
shape: (2, 9)
runmachinecpunanuqrowsnanuq in-memorynanuq streamingpython in-memorypython streaming
strstrstrstri64f64f64f64f64
"2026-11-02T14:10""claude-sandbox""Intel(R) Xeon(R) Processor @ 2โ€ฆ"0.6.0"1000000020.65null26.2418.14
"2026-11-02T14:25""claude-sandbox""Intel(R) Xeon(R) Processor @ 2โ€ฆ"0.6.0"1000000025.919.0324.7118.28

And question by question, on the latest run:

let byQuestion = times
  .filter(col.run == col.run.max)
  .withColumns(col.seconds.round(3))
  .pivot(on = "engine", index = "question", values = "seconds", sortColumns = true)
shape: (15, 5)
questionnanuq in-memorynanuq streamingpython in-memorypython streaming
strf64f64f64f64
"g1"0.5470.5440.4830.455
"g2"1.0010.7380.8140.574
"g3"1.0550.891.0580.79
"g4"0.7160.6590.5520.556
"g5"0.9450.8110.8460.732
"g6"1.0280.9310.7260.798
"g7"0.9990.7910.8260.698
"g8"1.1251.0851.0591.093
"g9"1.2160.6450.8850.565
"g10"3.1482.0443.691.525
"j1"1.8461.4761.8891.533
"j2"2.0611.3882.0861.549
"j3"1.8821.5091.8641.647
"j4"2.0051.5552.0451.628
"j5"6.3293.9585.8824.134

The benchmark

db-benchmark times dataframe libraries and databases on two tasks: ten group-by questions on a table of 10 million to 1 billion rows, and five joins. It is the benchmark where Polars first made its name, in 2021, and it is still run on every new version of the tools it covers.

The group-by table has six id columns of different kinds and sizes and three values:

column what groups
id1, id2 strings id001โ€ฆ K (100)
id3 strings id0000000001โ€ฆ N/K
id4, id5 integers K
id6 integers N/K
v1, v2 integers in 1โ€“5 and 1โ€“15
v3 a float in [0, 100)

The join tables are a left table x of N rows and three right tables of N/10โถ (small), N/10ยณ (medium) and N rows (big), whose keys overlap 90% with x's.

The questions are in bench/dbbench.nim and bench/dbbench.py. When the book is built, each one runs on both sides on 10,000 rows, and the build checks that the two tables are the same (sorted by their keys, so that the rows shown match).

Group-by questions

g1: sum v1 by id1

proc g1*(x: LazyFrame): LazyFrame =
  ## sum v1 by id1
  x.groupBy("id1").agg(col.v1.sum.alias("v1_sum"))
shape: (100, 2)
id1v1_sum
cati32
"id001"286
"id002"270
"id003"324
"id004"323
"id005"316
……
"id096"330
"id097"219
"id098"303
"id099"306
"id100"300

g2: sum v1 by id1:id2

proc g2*(x: LazyFrame): LazyFrame =
  ## sum v1 by id1:id2
  x.groupBy("id1", "id2").agg(col.v1.sum.alias("v1_sum"))
shape: (6_316, 3)
id1id2v1_sum
catcati32
"id001""id002"2
"id001""id005"9
"id001""id006"2
"id001""id007"7
"id001""id008"4
………
"id100""id095"9
"id100""id096"1
"id100""id097"4
"id100""id098"13
"id100""id100"1

g3: sum v1 mean v3 by id3

proc g3*(x: LazyFrame): LazyFrame =
  ## sum v1 mean v3 by id3
  x.groupBy("id3").agg(col.v1.sum.alias("v1_sum"), col.v3.mean.alias("v3_mean"))
shape: (100, 3)
id3v1_sumv3_mean
cati32f64
"id0000000001"33554.082505
"id0000000002"25649.287781
"id0000000003"27853.871425
"id0000000004"30951.090055
"id0000000005"27354.813354
………
"id0000000096"33252.427157
"id0000000097"30754.555622
"id0000000098"26446.759033
"id0000000099"30248.80176
"id0000000100"27256.616213

g4: mean v1:v3 by id4

proc g4*(x: LazyFrame): LazyFrame =
  ## mean v1:v3 by id4
  x.groupBy("id4").agg(col.v1.mean.alias("v1_mean"), col.v2.mean.alias("v2_mean"),
                       col.v3.mean.alias("v3_mean"))
shape: (100, 4)
id4v1_meanv2_meanv3_mean
i32f64f64f64
12.983747.71544745.562441
22.9611657.74757351.106608
33.1460677.89887652.24703
42.8269237.84615445.140535
52.9126218.20388350.60851
…………
962.778.2245.680176
973.0326098.2608751.217574
982.9417487.81553446.405132
993.048.2350.539987
1003.0106387.88297949.862361

g5: sum v1:v3 by id6

proc g5*(x: LazyFrame): LazyFrame =
  ## sum v1:v3 by id6
  x.groupBy("id6").agg(col.v1.sum.alias("v1_sum"), col.v2.sum.alias("v2_sum"),
                       col.v3.sum.alias("v3_sum"))
shape: (100, 4)
id6v1_sumv2_sumv3_sum
i32i32i32f64
12896724819.901325
23059275624.686782
32698304773.060168
43378545693.493764
53329215251.951351
…………
962818194801.252673
972937314722.388982
983339375507.241385
992888334894.383037
1003458565321.822027

g6: median v3 sd v3 by id4 id5

proc g6*(x: LazyFrame): LazyFrame =
  ## median v3 sd v3 by id4 id5
  x.groupBy("id4", "id5").agg(col.v3.median.alias("v3_median"), col.v3.std.alias("v3_std"))
shape: (6_245, 4)
id4id5v3_medianv3_std
i32i32f64f64
1219.81895914.835572
1356.74461949.498784
1579.85538914.947513
1679.940378null
1718.429828null
…………
1009422.9057624.587197
1009599.495246null
1009662.52736520.259614
1009933.358999null
10010015.911042null

g7: max v1 - min v2 by id3

proc g7*(x: LazyFrame): LazyFrame =
  ## max v1 - min v2 by id3
  x.groupBy("id3").agg((col.v1.max - col.v2.min).alias("range_v1_v2"))
shape: (100, 2)
id3range_v1_v2
cati32
"id0000000001"4
"id0000000002"4
"id0000000003"4
"id0000000004"4
"id0000000005"4
……
"id0000000096"4
"id0000000097"4
"id0000000098"4
"id0000000099"4
"id0000000100"4

g8: largest two v3 by id6

proc g8*(x: LazyFrame): LazyFrame =
  ## largest two v3 by id6
  x.dropNulls("v3").groupBy("id6").agg(col.v3.topK(2).alias("largest2_v3"))
    .explode("largest2_v3")
shape: (200, 2)
id6largest2_v3
i32f64
199.28818
199.868033
298.009352
299.763516
399.476037
……
9899.408389
9998.77951
9999.625273
10099.32078
10099.891088

g9: regression v1 v2 by id2 id4

proc g9*(x: LazyFrame): LazyFrame =
  ## regression v1 v2 by id2 id4
  x.groupBy("id2", "id4").agg(corr("v1", "v2").pow(2).alias("r2"))
shape: (6_324, 3)
id2id4r2
cati32f64
"id001"11.0
"id001"20.175824
"id001"3NaN
"id001"4NaN
"id001"7NaN
………
"id100"93NaN
"id100"94NaN
"id100"97NaN
"id100"98NaN
"id100"990.489382

g10: sum v3 count by id1:id6

proc g10*(x: LazyFrame): LazyFrame =
  ## sum v3 count by id1:id6
  x.groupBy("id1", "id2", "id3", "id4", "id5", "id6")
    .agg(col.v3.sum.alias("v3"), len().alias("count"))
shape: (10_000, 8)
id1id2id3id4id5id6v3count
catcatcati32i32i32f64u32
"id001""id002""id0000000059"98532311.4536231
"id001""id005""id0000000011"20673096.0946891
"id001""id005""id0000000065"27802329.1516171
"id001""id006""id0000000051"26959677.6267821
"id001""id007""id0000000019"15448931.0323761
……………………
"id100""id098""id0000000015"35589494.8883891
"id100""id098""id0000000024"10679868.6478091
"id100""id098""id0000000032"66549366.2159421
"id100""id098""id0000000076"84914761.0424461
"id100""id100""id0000000080"38795092.3267131

Join questions

j1: small inner on int

proc j1*(t: JoinTables): LazyFrame =
  ## small inner on int
  t.x.join(t.small, on = ["id1"])
shape: (8_972, 9)
id1id2id3id4id5id6v1id4_rightv2
i32i32i32catcatcatf32catf32
2210"id2""id2""id10"37.221138"id2"83.823555
221727"id2""id2""id1727"5.158724"id2"83.823555
222092"id2""id2""id2092"43.574284"id2"83.823555
223306"id2""id2""id3306"51.576077"id2"83.823555
224569"id2""id2""id4569"12.448287"id2"83.823555
………………………
111086037"id11""id108""id6037"39.281113"id11"95.907318
111087655"id11""id108""id7655"88.79631"id11"95.907318
111088030"id11""id108""id8030"45.440418"id11"95.907318
111088276"id11""id108""id8276"60.417381"id11"95.907318
111088524"id11""id108""id8524"22.404985"id11"95.907318

j2: medium inner on int

proc j2*(t: JoinTables): LazyFrame =
  ## medium inner on int
  t.x.join(t.medium, on = ["id2"])
shape: (9_100, 11)
id1id2id3id4id5id6v1id1_rightid4_rightid5_rightv2
i32i32i32catcatcatf32i32catcatf32
2210"id2""id2""id10"37.2211381"id1""id2"42.161072
221727"id2""id2""id1727"5.1587241"id1""id2"42.161072
222092"id2""id2""id2092"43.5742841"id1""id2"42.161072
223306"id2""id2""id3306"51.5760771"id1""id2"42.161072
224569"id2""id2""id4569"12.4482871"id1""id2"42.161072
……………………………
111086037"id11""id108""id6037"39.2811139"id9""id108"98.272331
111087655"id11""id108""id7655"88.796319"id9""id108"98.272331
111088030"id11""id108""id8030"45.4404189"id9""id108"98.272331
111088276"id11""id108""id8276"60.4173819"id9""id108"98.272331
111088524"id11""id108""id8524"22.4049859"id9""id108"98.272331

j3: medium outer on int

proc j3*(t: JoinTables): LazyFrame =
  ## medium outer on int (a left join, as in db-benchmark)
  t.x.join(t.medium, on = ["id2"], how = Left)
shape: (10_000, 11)
id1id2id3id4id5id6v1id1_rightid4_rightid5_rightv2
i32i32i32catcatcatf32i32catcatf32
2210"id2""id2""id10"37.2211381"id1""id2"42.161072
221727"id2""id2""id1727"5.1587241"id1""id2"42.161072
222092"id2""id2""id2092"43.5742841"id1""id2"42.161072
223306"id2""id2""id3306"51.5760771"id1""id2"42.161072
224569"id2""id2""id4569"12.4482871"id1""id2"42.161072
……………………………
111086037"id11""id108""id6037"39.2811139"id9""id108"98.272331
111087655"id11""id108""id7655"88.796319"id9""id108"98.272331
111088030"id11""id108""id8030"45.4404189"id9""id108"98.272331
111088276"id11""id108""id8276"60.4173819"id9""id108"98.272331
111088524"id11""id108""id8524"22.4049859"id9""id108"98.272331

j4: medium inner on factor

proc j4*(t: JoinTables): LazyFrame =
  ## medium inner on factor
  t.x.join(t.medium, on = ["id5"])
shape: (9_100, 11)
id1id2id3id4id5id6v1id1_rightid2_rightid4_rightv2
i32i32i32catcatcatf32i32i32catf32
2210"id2""id2""id10"37.22113812"id1"42.161072
221727"id2""id2""id1727"5.15872412"id1"42.161072
222092"id2""id2""id2092"43.57428412"id1"42.161072
223306"id2""id2""id3306"51.57607712"id1"42.161072
224569"id2""id2""id4569"12.44828712"id1"42.161072
……………………………
111086037"id11""id108""id6037"39.2811139108"id9"98.272331
111087655"id11""id108""id7655"88.796319108"id9"98.272331
111088030"id11""id108""id8030"45.4404189108"id9"98.272331
111088276"id11""id108""id8276"60.4173819108"id9"98.272331
111088524"id11""id108""id8524"22.4049859108"id9"98.272331

j5: big inner on int

proc j5*(t: JoinTables): LazyFrame =
  ## big inner on int
  t.x.join(t.big, on = ["id3"])
shape: (9_000, 13)
id1id2id3id4id5id6v1id1_rightid2_rightid4_rightid5_rightid6_rightv2
i32i32i32catcatcatf32i32i32catcatcatf32
2210"id2""id2""id10"37.221138634"id6""id34""id10"6.600459
221727"id2""id2""id1727"5.1587241023"id10""id23""id1727"46.574547
222092"id2""id2""id2092"43.5742841097"id10""id97""id2092"67.648369
223306"id2""id2""id3306"51.576077884"id8""id84""id3306"15.445398
224569"id2""id2""id4569"12.448287375"id3""id75""id4569"59.754215
…………………………………
111086037"id11""id108""id6037"39.281113922"id9""id22""id6037"8.298156
111087655"id11""id108""id7655"88.79631623"id6""id23""id7655"69.442337
111088030"id11""id108""id8030"45.4404186107"id6""id107""id8030"83.096092
111088276"id11""id108""id8276"60.41738171"id7""id1""id8276"59.613743
111088524"id11""id108""id8524"22.404985787"id7""id87""id8524"99.756798

Running it on your machine

From the root of a clone of the book, with Nim, nimble, uv and git (the script installs the book's dependencies first; the data goes to bench-data/, which git ignores; 10 million rows are about 0.5 GB of group-by CSV and 0.7 GB of join CSV):

scripts/bench dbbench                            # 10 million rows, 3 timed runs per question
scripts/bench dbbench -d:benchRows=100000000     # 100 million rows
scripts/bench dbbench -d:benchLabel=my-laptop    # a name for your machine

It writes the timings and the machine's specs to a timestamped file in results/dbbench/ and commits it; a pull request with that file adds a run to the tables at the top.

Source files

Every source file this page mentions, folded: tap one to read it. A file's name in the text leads here.

bench/dbbench.nim 186 lines
## The db-benchmark (H2O.ai, now DuckDB Labs) group-by and join questions in Nanuq,
## and data generators that follow its R scripts.
##
## Ported from db-benchmark's `polars/groupby-polars.py` and `polars/join-polars.py`
## (MPL-2.0); the generators follow `_data/groupby-datagen.R` and `_data/join-datagen.R`.
import std/[os, random, strutils, sequtils]
import nanuq

# --- Data ---------------------------------------------------------------------------

proc fmtId(prefix: string, n, width: int): string = prefix & align($n, width, '0')

proc generateGroupBy*(path: string, n, k: int, seed = 108) =
  ## `n` rows of the group-by table, as `groupby-datagen.R` makes them with `k` groups
  ## (no missing values, random order): id1, id2 (k strings each), id3 (n/k strings),
  ## id4, id5 (k ints), id6 (n/k ints), v1 in 1..5, v2 in 1..15, v3 in [0, 100).
  var r = initRand(seed)
  var f = open(path, fmWrite)
  defer: f.close()
  f.writeLine "id1,id2,id3,id4,id5,id6,v1,v2,v3"
  let nk = max(n div k, 1)
  for _ in 0 ..< n:
    f.writeLine fmtId("id", r.rand(1 .. k), 3), ',', fmtId("id", r.rand(1 .. k), 3), ',',
      fmtId("id", r.rand(1 .. nk), 10), ',', r.rand(1 .. k), ',', r.rand(1 .. k), ',',
      r.rand(1 .. nk), ',', r.rand(1 .. 5), ',', r.rand(1 .. 15), ',',
      formatFloat(r.rand(100.0), ffDecimal, 6)

type JoinSizes* = tuple[small, medium, big: int]

proc joinSizes*(n: int): JoinSizes =
  ## Rows of the three right-hand tables: n/1e6, n/1e3 and n in db-benchmark (whose
  ## smallest x has 1e7 rows); at least 10 and 100 here, so small samples join too.
  (max(n div 1_000_000, 10), max(n div 1_000, 100), n)

proc generateJoin*(dir: string, n: int, seed = 108) =
  ## The join tables as `join-datagen.R` makes them: `x.csv` (`n` rows) and `small.csv`,
  ## `medium.csv`, `big.csv`. Each key column draws from its own pool of keys: 90% are
  ## shared by both sides, 10% only on the left, 10% only on the right; id4..id6 are the
  ## same keys as strings.
  var r = initRand(seed)
  let sizes = joinSizes(n)
  proc split(m: int): tuple[x, l, rr: seq[int]] =
    var key = toSeq(1 .. (m * 11) div 10)
    r.shuffle(key)
    let a = (m * 9) div 10
    (key[0 ..< a], key[a ..< m], key[m .. ^1])
  proc sampleAll(keys: seq[int], size: int): seq[int] =
    # every key at least once, then random ones, shuffled
    result = keys
    while result.len < size: result.add keys[r.rand(keys.high)]
    result.setLen size
    r.shuffle(result)
  let k1 = split(sizes.small)
  let k2 = split(sizes.medium)
  let k3 = split(sizes.big)
  createDir dir
  block:
    let id1 = sampleAll(k1.x & k1.l, n)
    let id2 = sampleAll(k2.x & k2.l, n)
    let id3 = sampleAll(k3.x & k3.l, n)
    var f = open(dir / "x.csv", fmWrite)
    f.writeLine "id1,id2,id3,id4,id5,id6,v1"
    for i in 0 ..< n:
      f.writeLine id1[i], ',', id2[i], ',', id3[i], ",id", id1[i], ",id", id2[i], ",id", id3[i],
        ',', formatFloat(r.rand(100.0), ffDecimal, 6)
    f.close()
  block:
    let id1 = sampleAll(k1.x & k1.rr, sizes.small)
    var f = open(dir / "small.csv", fmWrite)
    f.writeLine "id1,id4,v2"
    for i in 0 ..< sizes.small:
      f.writeLine id1[i], ",id", id1[i], ',', formatFloat(r.rand(100.0), ffDecimal, 6)
    f.close()
  block:
    let id1 = sampleAll(k1.x & k1.rr, sizes.medium)
    let id2 = sampleAll(k2.x & k2.rr, sizes.medium)
    var f = open(dir / "medium.csv", fmWrite)
    f.writeLine "id1,id2,id4,id5,v2"
    for i in 0 ..< sizes.medium:
      f.writeLine id1[i], ',', id2[i], ",id", id1[i], ",id", id2[i], ',',
        formatFloat(r.rand(100.0), ffDecimal, 6)
    f.close()
  block:
    let id1 = sampleAll(k1.x & k1.rr, sizes.big)
    let id2 = sampleAll(k2.x & k2.rr, sizes.big)
    let id3 = sampleAll(k3.x & k3.rr, sizes.big)
    var f = open(dir / "big.csv", fmWrite)
    f.writeLine "id1,id2,id3,id4,id5,id6,v2"
    for i in 0 ..< sizes.big:
      f.writeLine id1[i], ',', id2[i], ',', id3[i], ",id", id1[i], ",id", id2[i], ",id", id3[i],
        ',', formatFloat(r.rand(100.0), ffDecimal, 6)
    f.close()

# --- Reading, as the Polars scripts do ----------------------------------------------

proc scanGroupBy*(path: string): LazyFrame =
  ## The group-by table, with its string ids as Categorical.
  scanCsv(path, schemaOverrides = {"id4": Int32, "id5": Int32, "id6": Int32,
                                   "v1": Int32, "v2": Int32, "v3": Float64})
    .withColumns(col(["id1", "id2", "id3"]).cast(Categorical))

type JoinTables* = object
  x*, small*, medium*, big*: LazyFrame

proc scanJoin*(dir: string): JoinTables =
  ## The four join tables, with their string ids as Categorical.
  JoinTables(
    x: scanCsv(dir / "x.csv", schemaOverrides = {"id1": Int32, "id2": Int32, "id3": Int32,
                                                 "v1": Float32})
      .withColumns(col(["id4", "id5", "id6"]).cast(Categorical)),
    small: scanCsv(dir / "small.csv", schemaOverrides = {"id1": Int32, "v2": Float32})
      .withColumns(col.id4.cast(Categorical)),
    medium: scanCsv(dir / "medium.csv", schemaOverrides = {"id1": Int32, "id2": Int32,
                                                           "v2": Float32})
      .withColumns(col(["id4", "id5"]).cast(Categorical)),
    big: scanCsv(dir / "big.csv", schemaOverrides = {"id1": Int32, "id2": Int32, "id3": Int32,
                                                     "v2": Float32})
      .withColumns(col(["id4", "id5", "id6"]).cast(Categorical)))

# --- Group-by questions ---------------------------------------------------------------

proc g1*(x: LazyFrame): LazyFrame =
  ## sum v1 by id1
  x.groupBy("id1").agg(col.v1.sum.alias("v1_sum"))

proc g2*(x: LazyFrame): LazyFrame =
  ## sum v1 by id1:id2
  x.groupBy("id1", "id2").agg(col.v1.sum.alias("v1_sum"))

proc g3*(x: LazyFrame): LazyFrame =
  ## sum v1 mean v3 by id3
  x.groupBy("id3").agg(col.v1.sum.alias("v1_sum"), col.v3.mean.alias("v3_mean"))

proc g4*(x: LazyFrame): LazyFrame =
  ## mean v1:v3 by id4
  x.groupBy("id4").agg(col.v1.mean.alias("v1_mean"), col.v2.mean.alias("v2_mean"),
                       col.v3.mean.alias("v3_mean"))

proc g5*(x: LazyFrame): LazyFrame =
  ## sum v1:v3 by id6
  x.groupBy("id6").agg(col.v1.sum.alias("v1_sum"), col.v2.sum.alias("v2_sum"),
                       col.v3.sum.alias("v3_sum"))

proc g6*(x: LazyFrame): LazyFrame =
  ## median v3 sd v3 by id4 id5
  x.groupBy("id4", "id5").agg(col.v3.median.alias("v3_median"), col.v3.std.alias("v3_std"))

proc g7*(x: LazyFrame): LazyFrame =
  ## max v1 - min v2 by id3
  x.groupBy("id3").agg((col.v1.max - col.v2.min).alias("range_v1_v2"))

proc g8*(x: LazyFrame): LazyFrame =
  ## largest two v3 by id6
  x.dropNulls("v3").groupBy("id6").agg(col.v3.topK(2).alias("largest2_v3"))
    .explode("largest2_v3")

proc g9*(x: LazyFrame): LazyFrame =
  ## regression v1 v2 by id2 id4
  x.groupBy("id2", "id4").agg(corr("v1", "v2").pow(2).alias("r2"))

proc g10*(x: LazyFrame): LazyFrame =
  ## sum v3 count by id1:id6
  x.groupBy("id1", "id2", "id3", "id4", "id5", "id6")
    .agg(col.v3.sum.alias("v3"), len().alias("count"))

# --- Join questions -------------------------------------------------------------------

proc j1*(t: JoinTables): LazyFrame =
  ## small inner on int
  t.x.join(t.small, on = ["id1"])

proc j2*(t: JoinTables): LazyFrame =
  ## medium inner on int
  t.x.join(t.medium, on = ["id2"])

proc j3*(t: JoinTables): LazyFrame =
  ## medium outer on int (a left join, as in db-benchmark)
  t.x.join(t.medium, on = ["id2"], how = Left)

proc j4*(t: JoinTables): LazyFrame =
  ## medium inner on factor
  t.x.join(t.medium, on = ["id5"])

proc j5*(t: JoinTables): LazyFrame =
  ## big inner on int
  t.x.join(t.big, on = ["id3"])

bench/dbbench.nim

bench/dbbench.py 114 lines
"""The db-benchmark (H2O.ai, now DuckDB Labs) group-by and join questions in Python Polars.

The queries are those of db-benchmark's polars/groupby-polars.py and polars/join-polars.py
(MPL-2.0), as functions of the lazy tables.
"""
import os

import polars as pl
from polars import col


def scan_groupby(path):
    # The group-by table, with its string ids as Categorical.
    return pl.scan_csv(
        path,
        schema_overrides={"id4": pl.Int32, "id5": pl.Int32, "id6": pl.Int32,
                          "v1": pl.Int32, "v2": pl.Int32, "v3": pl.Float64},
    ).with_columns(pl.col(["id1", "id2", "id3"]).cast(pl.Categorical))


def scan_join(dir):
    # The four join tables, with their string ids as Categorical.
    def scan(name, overrides, cats):
        return pl.scan_csv(os.path.join(dir, name + ".csv"), schema_overrides=overrides) \
            .with_columns(pl.col(cats).cast(pl.Categorical))
    return {
        "x": scan("x", {"id1": pl.Int32, "id2": pl.Int32, "id3": pl.Int32, "v1": pl.Float32},
                  ["id4", "id5", "id6"]),
        "small": scan("small", {"id1": pl.Int32, "v2": pl.Float32}, ["id4"]),
        "medium": scan("medium", {"id1": pl.Int32, "id2": pl.Int32, "v2": pl.Float32},
                       ["id4", "id5"]),
        "big": scan("big", {"id1": pl.Int32, "id2": pl.Int32, "id3": pl.Int32,
                            "v2": pl.Float32}, ["id4", "id5", "id6"]),
    }


def g1(x):
    # sum v1 by id1
    return x.group_by("id1").agg(pl.sum("v1").alias("v1_sum"))


def g2(x):
    # sum v1 by id1:id2
    return x.group_by(["id1", "id2"]).agg(pl.sum("v1").alias("v1_sum"))


def g3(x):
    # sum v1 mean v3 by id3
    return x.group_by("id3").agg([pl.sum("v1").alias("v1_sum"), pl.mean("v3").alias("v3_mean")])


def g4(x):
    # mean v1:v3 by id4
    return x.group_by("id4").agg([pl.mean("v1").alias("v1_mean"), pl.mean("v2").alias("v2_mean"),
                                  pl.mean("v3").alias("v3_mean")])


def g5(x):
    # sum v1:v3 by id6
    return x.group_by("id6").agg([pl.sum("v1").alias("v1_sum"), pl.sum("v2").alias("v2_sum"),
                                  pl.sum("v3").alias("v3_sum")])


def g6(x):
    # median v3 sd v3 by id4 id5
    return x.group_by(["id4", "id5"]).agg([pl.median("v3").alias("v3_median"),
                                           pl.std("v3").alias("v3_std")])


def g7(x):
    # max v1 - min v2 by id3
    return x.group_by("id3").agg([(pl.max("v1") - pl.min("v2")).alias("range_v1_v2")])


def g8(x):
    # largest two v3 by id6
    return x.drop_nulls("v3").group_by("id6").agg(col("v3").top_k(2).alias("largest2_v3")) \
        .explode("largest2_v3")


def g9(x):
    # regression v1 v2 by id2 id4
    return x.group_by(["id2", "id4"]).agg((pl.corr("v1", "v2", method="pearson") ** 2).alias("r2"))


def g10(x):
    # sum v3 count by id1:id6
    return x.group_by(["id1", "id2", "id3", "id4", "id5", "id6"]) \
        .agg([pl.sum("v3").alias("v3"), pl.len().alias("count")])


def j1(t):
    # small inner on int
    return t["x"].join(t["small"], on="id1")


def j2(t):
    # medium inner on int
    return t["x"].join(t["medium"], on="id2")


def j3(t):
    # medium outer on int (a left join, as in db-benchmark)
    return t["x"].join(t["medium"], how="left", on="id2")


def j4(t):
    # medium inner on factor
    return t["x"].join(t["medium"], on="id5")


def j5(t):
    # big inner on int
    return t["x"].join(t["big"], on="id3")

bench/dbbench.py

book/benchkit.nim: timing, results and tables of the benchmark chapters 138 lines
## Helpers for the benchmark chapters.
##
## A benchmark chapter builds in two ways:
## - normally (`nimble genbook`, CI): it runs its queries on a small sample, to check
##   that Nim and Python agree, and shows every result file in `results/<bench>/`,
##   as a Nanuq query over those files;
## - with `-d:bench` (`scripts/bench <bench>`, on your machine): it first runs the
##   benchmark at full size, times the Nim and the Python queries, writes a timestamped
##   JSON file with the timings and the machine's specs to `results/<bench>/`, and
##   commits it.
import std/[json, options, os, osproc, strutils, times, monotimes, sequtils, math, xmltree]
import nanuq
import nanuqbook

const
  benchRuns* {.intdefine.} = 3        ## timed runs of each query (the best one counts)
  benchLabel* {.strdefine.} = ""      ## a name for the machine, such as "pietro-mac"

proc resultsDir*(bench: string): string =
  ## results/<bench>, seen from the chapter's working directory (docs/).
  ".." / "results" / bench

proc cmd(c: string): string =
  try:
    let (o, code) = execCmdEx(c)
    if code == 0: o.strip else: ""
  except OSError: ""

proc systemInfo*(): JsonNode =
  ## The machine the benchmark runs on.
  var cpu, memBytes: string
  when defined(macosx):
    cpu = cmd("sysctl -n machdep.cpu.brand_string")
    memBytes = cmd("sysctl -n hw.memsize")
  else:
    for line in cmd("cat /proc/cpuinfo").splitLines:
      if line.startsWith("model name"):
        cpu = line.split(':', 1)[1].strip
        break
    for line in cmd("cat /proc/meminfo").splitLines:
      if line.startsWith("MemTotal:"):
        memBytes = $(parseInt(line.splitWhitespace[1]) * 1024)
  let memGb = if memBytes.len > 0: round(parseFloat(memBytes) / 1e9, 1) else: 0.0
  var osName = cmd("uname -sr")
  when defined(macosx):
    osName = "macOS " & cmd("sw_vers -productVersion")
  %*{"os": osName, "arch": hostCPU, "cpu": cpu, "cores": countProcessors(),
     "memoryGB": memGb}

proc timeIt*(runs: int, body: proc ()): seq[float] =
  ## Seconds taken by each of `runs` runs of `body`.
  for _ in 1 .. runs:
    let start = getMonoTime()
    body()
    result.add (getMonoTime() - start).inNanoseconds.float / 1e9

proc timePython*(runs: int, call: string): seq[float] =
  ## Seconds taken by each of `runs` runs of the Python expression `call`, in the
  ## chapter's Python session.
  let (printed, _) = runPython("""
import time as _time
_times = []
for _ in range(""" & $runs & """):
    _start = _time.perf_counter()
    """ & call & """

    _times.append(_time.perf_counter() - _start)
print(" ".join(repr(t) for t in _times))
""")
  printed.splitWhitespace.mapIt(parseFloat(it))

proc pythonVersions*(): JsonNode =
  let (printed, _) = runPython("""
import platform as _platform, polars as _pl
print(_platform.python_version(), _pl.__version__)
""")
  let v = printed.splitWhitespace
  %*{"python": v[0], "pythonPolars": v[1]}

proc saveResult*(bench: string, params, timings: JsonNode): string =
  ## Writes results/<bench>/<timestamp>[-<label>].json and commits it. Returns its path.
  let now = now().utc
  var versions = %*{"nim": NimVersion, "nanuqWrapper": polarsWrapperVersion()}
  for k, v in pythonVersions(): versions[k] = v
  let data = %*{"benchmark": bench, "timestamp": now.format("yyyy-MM-dd'T'HH:mm:ss'Z'"),
                "label": benchLabel, "params": params, "system": systemInfo(),
                "versions": versions, "timings": timings}
  createDir resultsDir(bench)
  var name = now.format("yyyyMMdd'T'HHmmss'Z'")
  if benchLabel.len > 0: name.add "-" & benchLabel
  result = resultsDir(bench) / name & ".json"
  writeFile result, data.pretty & "\n"
  echo "[bench] wrote ", result
  let (o, code) = execCmdEx("git add " & quoteShell(result) & " && git commit -q -m " &
    quoteShell("Benchmark result: " & bench & " " & name) & " -- " & quoteShell(result))
  if code == 0: echo "[bench] committed ", result
  else: echo "[bench] could not commit ", result, ":\n", o

proc markdownTable*(df: DataFrame, boldLast = false): string =
  ## `df` as a Markdown table, as readers want it: capitalised headers, seconds with two
  ## decimals, rows with separators, "-" for nulls. `boldLast` is for a row of totals.
  let names = df.columns
  result = "| " & names.mapIt(it.capitalizeAscii).join(" | ") & " |\n| " &
    names.mapIt(if df.dtype(it) == String: "---" else: "--:").join(" | ") & " |\n"
  for i in 0 ..< df.height:
    var cells: seq[string]
    for name in names:
      let dtype = df.dtype(name)
      var cell = "-"
      if dtype == Float64:
        let x = df[name, i, Option[float]]
        if x.isSome: cell = formatFloat(x.get, ffDecimal, 2) & " s"
      elif dtype == Int64:
        cell = insertSep($df[name, i, int], ',')
      else:
        cell = df[name, i, string]
      cells.add (if boldLast and i == df.height - 1 and cell != "-": "**" & cell & "**" else: cell)
    result.add "| " & cells.join(" | ") & " |\n"

proc queryTabs*(nimSrc, pySrc: string, nimFrame: DataFrame, pyCall: string): string =
  ## A query's Nim and Python source in tabs, each with the table it gives (the Python
  ## one from running `pyCall`); fails the build if the two tables differ.
  let nimSide = "<pre><code class=\"nim-file nohighlight nim hljs\">" &
    highlightNim(nimSrc.strip) & "</code></pre>" & nimFrame.toHtml
  let (_, pyShown) = runPython(pyCall)
  checkSameFrame(nimSide, pyShown, pyCall)
  tabsHtml(nimSide, "<pre><code class=\"language-python py-file hljs\">" &
    xmltree.escape(pySrc.strip) & "</code></pre>" & pyShown)

proc sourcePart*(source, start: string, stops: openArray[string]): string =
  ## The part of `source` from the line starting with `start` to the next `stops`.
  let i = source.find(start)
  doAssert i >= 0, "not found: " & start
  var j = source.len
  for s in stops:
    let k = source.find(s, i + start.len)
    if k >= 0 and k < j: j = k
  source[i ..< j].strip

book/benchkit.nim

scripts/bench: a full run on your machine 23 lines
#!/bin/sh
# Runs a benchmark chapter of the book at full size, on this machine:
#
#   scripts/bench 1brc|pdsh|dbbench [nim options]
#
# e.g. `scripts/bench 1brc -d:benchRows=100000000 -d:benchLabel=my-laptop` or
# `scripts/bench pdsh -d:benchScale=10`.
# The chapter times the Nim and the Python queries, writes the timings and the
# machine's specs to results/<benchmark>/<timestamp>[-label].json, commits that
# file, and rebuilds its page. Needs Nim (with nimble), uv and git; run it from the
# repository root. It installs the book's Nim and Python dependencies first.
set -e
cd "$(dirname "$0")/.."
case "$1" in
  1brc) chapter=book/benchmarks/one_billion_rows.nim ;;
  pdsh) chapter=book/benchmarks/pds_h.nim ;;
  dbbench) chapter=book/benchmarks/db_benchmark.nim ;;
  *) echo "usage: scripts/bench 1brc|pdsh|dbbench [nim options]" >&2; exit 2 ;;
esac
shift
nimble install -y --depsOnly
uv sync --locked --quiet
exec uv run nim r -d:release -d:bench --hints:off "$@" "$chapter"

scripts/bench

import nanuq, nanuqbook, benchkit, dbbench
import ../foldcode
import std/[algorithm, os, json, strutils, sequtils]
bookInit()

const
  benchRows {.intdefine.} = 10_000_000  ## rows of a full run (`-d:benchRows=...`)
  benchGroups {.intdefine.} = 100       ## K, the number of groups of id1, id2, id4, id5

nbText: "# Group-by and join (db-benchmark)"

nanuq """
**About this chapter.** The questions are ported from the Polars scripts of
[db-benchmark](https://github.com/duckdblabs/db-benchmark) (started by H2O.ai, now kept by
DuckDB Labs), licensed under the
[Mozilla Public License 2.0](https://github.com/pietroppeter/nanuq-book/blob/main/licenses/db-benchmark-MPL-2.0.txt).
The data generators in [`bench/dbbench.nim`](#src-bench-dbbench-nim) follow its R scripts (`groupby-datagen.R` and
`join-datagen.R`), with Nim's random numbers, so the values differ from the R ones. The data
is made on the fly and never stored in the repository. The text is the book's own.

The code of the benchmark is folded under [Source files](#source-files), at the end.
"""

type
  GroupQ = tuple[name, title: string, keys: seq[string], run: proc (x: LazyFrame): LazyFrame]
  JoinQ = tuple[name, title: string, run: proc (t: JoinTables): LazyFrame]

let groupQs: seq[GroupQ] = @[
  ("g1", "sum v1 by id1", @["id1"], g1),
  ("g2", "sum v1 by id1:id2", @["id1", "id2"], g2),
  ("g3", "sum v1 mean v3 by id3", @["id3"], g3),
  ("g4", "mean v1:v3 by id4", @["id4"], g4),
  ("g5", "sum v1:v3 by id6", @["id6"], g5),
  ("g6", "median v3 sd v3 by id4 id5", @["id4", "id5"], g6),
  ("g7", "max v1 - min v2 by id3", @["id3"], g7),
  ("g8", "largest two v3 by id6", @["id6", "largest2_v3"], g8),
  ("g9", "regression v1 v2 by id2 id4", @["id2", "id4"], g9),
  ("g10", "sum v3 count by id1:id6", @["id1", "id2", "id3", "id4", "id5", "id6"], g10)]

let joinQs: seq[JoinQ] = @[
  ("j1", "small inner on int", j1),
  ("j2", "medium inner on int", j2),
  ("j3", "medium outer on int", j3),
  ("j4", "medium inner on factor", j4),
  ("j5", "big inner on int", j5)]

proc groupByFile(rows: int): string =
  result = ".." / "bench-data" / "dbbench" / "G1_" & $rows & "_" & $benchGroups & ".csv"
  if not fileExists(result):
    createDir result.parentDir
    generateGroupBy(result, rows, benchGroups)

proc joinDir(rows: int): string =
  result = ".." / "bench-data" / "dbbench" / "J1_" & $rows
  if not fileExists(result / "big.csv"):
    generateJoin(result, rows)

proc loadPython(gfile, jdir: string) =
  discard runPython("import sys\nsys.path.insert(0, '../bench')\nfrom dbbench import *\n" &
                    "_x = scan_groupby(" & escapeJson(gfile) & ")\n" &
                    "_t = scan_join(" & escapeJson(jdir) & ")")

# --- A full run: only with -d:bench -------------------------------------------------
when defined(bench):
  let gfile = groupByFile(benchRows)
  let jdir = joinDir(benchRows)
  let x = scanGroupBy(gfile)
  let t = scanJoin(jdir)
  loadPython(gfile, jdir)
  var nimMemory, nimStreaming, pyMemory, pyStreaming = newJObject()
  for q in groupQs:
    echo "[bench] ", q.name
    nimMemory[q.name] = %timeIt(benchRuns, proc () = discard q.run(x).collect(Engine.InMemory))
    nimStreaming[q.name] = %timeIt(benchRuns, proc () = discard q.run(x).collect(Engine.Streaming))
    pyMemory[q.name] = %timePython(benchRuns, q.name & "(_x).collect(engine='in-memory')")
    pyStreaming[q.name] = %timePython(benchRuns, q.name & "(_x).collect(engine='streaming')")
  for q in joinQs:
    echo "[bench] ", q.name
    nimMemory[q.name] = %timeIt(benchRuns, proc () = discard q.run(t).collect(Engine.InMemory))
    nimStreaming[q.name] = %timeIt(benchRuns, proc () = discard q.run(t).collect(Engine.Streaming))
    pyMemory[q.name] = %timePython(benchRuns, q.name & "(_t).collect(engine='in-memory')")
    pyStreaming[q.name] = %timePython(benchRuns, q.name & "(_t).collect(engine='streaming')")
  discard saveResult("dbbench", %*{"rows": benchRows, "groups": benchGroups, "runs": benchRuns},
    %*{"nanuq in-memory": nimMemory, "nanuq streaming": nimStreaming,
       "python in-memory": pyMemory, "python streaming": pyStreaming})

# --- Results ----------------------------------------------------------------------
nbText: """
## Results

Each run of the full benchmark leaves a JSON file in
[`results/dbbench/`](https://github.com/pietroppeter/nanuq-book/tree/main/results/dbbench),
with the machine, the versions and, for each engine and question, three timings. The tables
below are a Polars query over those files (`run` is when it started, in UTC), as in the other benchmark chapters: two rounds
of `unnest` and `unpivot` give one row per engine and question, and `list.min` keeps the
best of the timed runs.
"""

tabs """
import glob
import polars as pl

index = ["run", "machine", "cpu", "nanuq", "rows"]


def timings(path):
    return (
        pl.read_json(path)
        .select(
            pl.col("timestamp").str.slice(0, 16).alias("run"),
            pl.col("label").alias("machine"),
            pl.col("system").struct.field("cpu"),
            pl.col("versions").struct.field("nanuqWrapper").alias("nanuq"),
            pl.col("params").struct.field("rows"),
            "timings",
        )
        .unnest("timings")
        .unpivot(index=index, variable_name="engine", value_name="questions")
        .unnest("questions")
        .unpivot(index=[*index, "engine"], variable_name="question", value_name="seconds")
    )


times = pl.concat(
    [timings(path) for path in sorted(glob.glob("../results/dbbench/*.json"))]
).with_columns(pl.col("seconds").list.min())
times.head(3)
""":
  nbCode:
    let index = @["run", "machine", "cpu", "nanuq", "rows"]

    proc timings(path: string): DataFrame =
      readJson(path)
        .select(
          col.timestamp.str.slice(0, 16).alias("run"),
          col.label.alias("machine"),
          col.system.struct.field("cpu"),
          col.versions.struct.field("nanuqWrapper").alias("nanuq"),
          col.params.struct.field("rows"),
          col.timings)
        .unnest("timings")
        .unpivot(index = index, variableName = "engine", valueName = "questions")
        .unnest("questions")
        .unpivot(index = index & "engine", variableName = "question", valueName = "seconds")

    let times = concat(sorted(toSeq(walkFiles("../results/dbbench/*.json"))).mapIt(timings(it)),
                       how = ConcatMethod.Vertical)
      .withColumns(col.seconds.list.min)
    nbShow times.head(3)

nbText: """
The total time of each run, one column per engine:
"""

tabs """
(
    times.group_by([*index, "engine"], maintain_order=True)
    .agg(pl.col("seconds").sum().round(2))
    .pivot(on="engine", index=index, values="seconds", sort_columns=True)
)
""":
  nbCode:
    nbShow times
      .groupBy(index & "engine", maintainOrder = true)
      .agg(col.seconds.sum.round(2))
      .pivot(on = "engine", index = index, values = "seconds", sortColumns = true)

nbText: """
And question by question, on the latest run:
"""

tabs """
pl.Config.set_tbl_rows(15)  # the default shows 10 rows

(
    times.filter(pl.col("run") == pl.col("run").max())
    .with_columns(pl.col("seconds").round(3))
    .pivot(on="engine", index="question", values="seconds", sort_columns=True)
)
""":
  nbCode:
    let byQuestion = times
      .filter(col.run == col.run.max)
      .withColumns(col.seconds.round(3))
      .pivot(on = "engine", index = "question", values = "seconds", sortColumns = true)
  nbRawHtml: byQuestion.toHtml(maxRows = 15)  # the default shows 10 rows

discard runPython("pl.Config.set_tbl_rows(10)")

nanuq """
Timings are in seconds, reading the CSV files included.
"""

nbText: "## The benchmark"

nbText: """
[db-benchmark](https://duckdblabs.github.io/db-benchmark/) times dataframe libraries and
databases on two tasks: ten group-by questions on a table of 10 million to 1 billion rows,
and five joins. It is the benchmark where Polars first made its name, in 2021, and it is
still run on every new version of the tools it covers.

The group-by table has six id columns of different kinds and sizes and three values:

| column | what | groups |
| ------ | ---- | ------ |
| `id1`, `id2` | strings `id001`โ€ฆ | K (100) |
| `id3` | strings `id0000000001`โ€ฆ | N/K |
| `id4`, `id5` | integers | K |
| `id6` | integers | N/K |
| `v1`, `v2` | integers in 1โ€“5 and 1โ€“15 | |
| `v3` | a float in [0, 100) | |

The join tables are a left table `x` of N rows and three right tables of N/10โถ (`small`), N/10ยณ
(`medium`) and N rows (`big`), whose keys overlap 90% with `x`'s.
"""

nanuq """
As in db-benchmark's Polars scripts, both sides read the CSV files with the same schema
overrides and cast the string ids to `Categorical`. The scripts there first copy each table to
an Arrow IPC file and query that; here the queries scan the CSV files, so the timings include
reading them, as in the other benchmark chapters. Only the 10 million row, 100 group, no
missing values, unsorted variant is set up.
"""

nbText: """
The questions are in [`bench/dbbench.nim`](#src-bench-dbbench-nim)
and [`bench/dbbench.py`](#src-bench-dbbench-py).
When the book is built, each one runs on both sides on 10,000 rows, and the build checks that
the two tables are the same (sorted by their keys, so that the rows shown match).
"""

let nimSource = readFile(".." / "bench" / "dbbench.nim")
let pySource = readFile(".." / "bench" / "dbbench.py")

proc pyKeys(keys: seq[string]): string = "[" & keys.mapIt(escapeJson(it)).join(", ") & "]"

block:
  let gfile = groupByFile(10_000)
  let jdir = joinDir(10_000)
  let x = scanGroupBy(gfile)
  let t = scanJoin(jdir)
  loadPython(gfile, jdir)
  nbText: "## Group-by questions"
  for q in groupQs:
    nbText: "### " & q.name & ": " & q.title
    let nimSrc = sourcePart(nimSource, "proc " & q.name & "*", ["\nproc ", "\n# ---"])
    let pySrc = sourcePart(pySource, "def " & q.name & "(", ["\n\n\ndef "])
    nbRawHtml: queryTabs(nimSrc, pySrc, q.run(x).collect.sort(q.keys),
                         q.name & "(_x).collect().sort(" & pyKeys(q.keys) & ")")
  nbText: "## Join questions"
  for q in joinQs:
    nbText: "### " & q.name & ": " & q.title
    let nimSrc = sourcePart(nimSource, "proc " & q.name & "*", ["\nproc ", "\n# ---"])
    let pySrc = sourcePart(pySource, "def " & q.name & "(", ["\n\n\ndef "])
    nbRawHtml: queryTabs(nimSrc, pySrc, q.run(t).collect.sort(["id1", "id2", "id3"]),
                         q.name & "(_t).collect().sort(['id1', 'id2', 'id3'])")

nanuq """
Nanuq spells a few things differently: keys go in a list (`on = ["id1"]`), `pl.sum("v1")` is
`col.v1.sum`, `** 2` is `.pow(2)`, and Python's `method="pearson"` is Nanuq's default `how`.
"""

nbText: """
## Running it on your machine

From the root of a clone of the book, with Nim, nimble, uv and git (the script installs the
book's dependencies first; the data goes to `bench-data/`, which git ignores; 10 million rows
are about 0.5 GB of group-by CSV and 0.7 GB of join CSV):

```sh
scripts/bench dbbench                            # 10 million rows, 3 timed runs per question
scripts/bench dbbench -d:benchRows=100000000     # 100 million rows
scripts/bench dbbench -d:benchLabel=my-laptop    # a name for your machine
```

It writes the timings and the machine's specs to a timestamped file in `results/dbbench/`
and commits it; a pull request with that file adds a run to the tables at the top.
"""

nbSourceFiles:
  nbFoldCode "bench/dbbench.nim"
  nbFoldCode "bench/dbbench.py"
  nbFoldCode "book/benchkit.nim", title = "`book/benchkit.nim`: timing, results and tables of the benchmark chapters"
  nbFoldCode "scripts/bench", title = "`scripts/bench`: a full run on your machine"

bookSave()
Made with nimib and nimibook. Blocks marked "ran" were executed when this page was built.