|
| 1 | +/** |
| 2 | + * Benchmark: combineSeries / combineDataFrame — element-wise binary combine. |
| 3 | + * Outputs JSON: {"function": "combine", "mean_ms": ..., "iterations": ..., "total_ms": ...} |
| 4 | + */ |
| 5 | +import { Series, DataFrame, combineSeries, combineDataFrame } from "../../src/index.js"; |
| 6 | + |
| 7 | +const SIZE = 10_000; |
| 8 | +const WARMUP = 5; |
| 9 | +const ITERATIONS = 100; |
| 10 | + |
| 11 | +const a = new Series({ data: Array.from({ length: SIZE }, (_, i) => i), index: Array.from({ length: SIZE }, (_, i) => i) }); |
| 12 | +const b = new Series({ data: Array.from({ length: SIZE }, (_, i) => SIZE - i), index: Array.from({ length: SIZE }, (_, i) => i) }); |
| 13 | + |
| 14 | +const dfA = DataFrame.fromColumns({ |
| 15 | + x: Array.from({ length: SIZE }, (_, i) => i), |
| 16 | + y: Array.from({ length: SIZE }, (_, i) => i * 2), |
| 17 | +}); |
| 18 | +const dfB = DataFrame.fromColumns({ |
| 19 | + x: Array.from({ length: SIZE }, (_, i) => SIZE - i), |
| 20 | + z: Array.from({ length: SIZE }, (_, i) => i * 3), |
| 21 | +}); |
| 22 | + |
| 23 | +const addFn = (p: unknown, q: unknown) => (p as number) + (q as number); |
| 24 | + |
| 25 | +for (let i = 0; i < WARMUP; i++) { |
| 26 | + combineSeries(a, b, addFn, 0); |
| 27 | + combineDataFrame(dfA, dfB, addFn, { fillValue: 0 }); |
| 28 | +} |
| 29 | + |
| 30 | +const start = performance.now(); |
| 31 | +for (let i = 0; i < ITERATIONS; i++) { |
| 32 | + combineSeries(a, b, addFn, 0); |
| 33 | + combineDataFrame(dfA, dfB, addFn, { fillValue: 0 }); |
| 34 | +} |
| 35 | +const total = performance.now() - start; |
| 36 | + |
| 37 | +console.log( |
| 38 | + JSON.stringify({ |
| 39 | + function: "combine", |
| 40 | + mean_ms: total / ITERATIONS, |
| 41 | + iterations: ITERATIONS, |
| 42 | + total_ms: total, |
| 43 | + }), |
| 44 | +); |
0 commit comments