|
| 1 | +/** |
| 2 | + * Benchmark: alignDataFrame — align two 10k-row DataFrames on inner/outer join. |
| 3 | + * Outputs JSON: {"function": "align_dataframe", "mean_ms": ..., "iterations": ..., "total_ms": ...} |
| 4 | + */ |
| 5 | +import { DataFrame, Index, alignDataFrame } from "../../src/index.ts"; |
| 6 | + |
| 7 | +const SIZE = 10_000; |
| 8 | +const WARMUP = 5; |
| 9 | +const ITERATIONS = 30; |
| 10 | + |
| 11 | +const idxA = Array.from({ length: SIZE }, (_, i) => i * 2); |
| 12 | +const idxB = Array.from({ length: SIZE }, (_, i) => i * 3); |
| 13 | + |
| 14 | +const dfA = new DataFrame( |
| 15 | + { |
| 16 | + x: Array.from({ length: SIZE }, (_, i) => i * 1.0), |
| 17 | + y: Array.from({ length: SIZE }, (_, i) => i * 2.0), |
| 18 | + z: Array.from({ length: SIZE }, (_, i) => i * 3.0), |
| 19 | + }, |
| 20 | + { index: new Index(idxA) }, |
| 21 | +); |
| 22 | + |
| 23 | +const dfB = new DataFrame( |
| 24 | + { |
| 25 | + y: Array.from({ length: SIZE }, (_, i) => i * 10.0), |
| 26 | + z: Array.from({ length: SIZE }, (_, i) => i * 20.0), |
| 27 | + w: Array.from({ length: SIZE }, (_, i) => i * 30.0), |
| 28 | + }, |
| 29 | + { index: new Index(idxB) }, |
| 30 | +); |
| 31 | + |
| 32 | +for (let i = 0; i < WARMUP; i++) { |
| 33 | + alignDataFrame(dfA, dfB, { join: "inner" }); |
| 34 | + alignDataFrame(dfA, dfB, { join: "outer" }); |
| 35 | + alignDataFrame(dfA, dfB, { join: "left" }); |
| 36 | +} |
| 37 | + |
| 38 | +const start = performance.now(); |
| 39 | +for (let i = 0; i < ITERATIONS; i++) { |
| 40 | + alignDataFrame(dfA, dfB, { join: "inner" }); |
| 41 | + alignDataFrame(dfA, dfB, { join: "outer" }); |
| 42 | + alignDataFrame(dfA, dfB, { join: "left" }); |
| 43 | +} |
| 44 | +const total = performance.now() - start; |
| 45 | + |
| 46 | +console.log( |
| 47 | + JSON.stringify({ |
| 48 | + function: "align_dataframe", |
| 49 | + mean_ms: total / ITERATIONS, |
| 50 | + iterations: ITERATIONS, |
| 51 | + total_ms: total, |
| 52 | + }), |
| 53 | +); |
0 commit comments