|
| 1 | +/** |
| 2 | + * Benchmark: clipAdvancedSeries / clipAdvancedDataFrame — per-element clipping with array bounds. |
| 3 | + * Outputs JSON: {"function": "clip_advanced", "mean_ms": ..., "iterations": ..., "total_ms": ...} |
| 4 | + */ |
| 5 | +import { Series, DataFrame, clipAdvancedSeries, clipAdvancedDataFrame } from "../../src/index.ts"; |
| 6 | + |
| 7 | +const ROWS = 50_000; |
| 8 | +const WARMUP = 5; |
| 9 | +const ITERATIONS = 30; |
| 10 | + |
| 11 | +const data = Float64Array.from({ length: ROWS }, (_, i) => Math.sin(i * 0.01) * 200); |
| 12 | +const lower = Float64Array.from({ length: ROWS }, () => -50); |
| 13 | +const upper = Float64Array.from({ length: ROWS }, () => 50); |
| 14 | +const s = new Series(data); |
| 15 | +const lowerArr = Array.from(lower); |
| 16 | +const upperArr = Array.from(upper); |
| 17 | + |
| 18 | +const dfCols: Record<string, number[]> = {}; |
| 19 | +for (let c = 0; c < 5; c++) { |
| 20 | + dfCols[`col${c}`] = Array.from({ length: ROWS }, (_, i) => Math.sin((i + c) * 0.01) * 200); |
| 21 | +} |
| 22 | +const df = new DataFrame(dfCols); |
| 23 | + |
| 24 | +for (let i = 0; i < WARMUP; i++) { |
| 25 | + clipAdvancedSeries(s, { lower: lowerArr, upper: upperArr }); |
| 26 | + clipAdvancedDataFrame(df, { lower: -50, upper: 50 }); |
| 27 | +} |
| 28 | + |
| 29 | +const start = performance.now(); |
| 30 | +for (let i = 0; i < ITERATIONS; i++) { |
| 31 | + clipAdvancedSeries(s, { lower: lowerArr, upper: upperArr }); |
| 32 | + clipAdvancedDataFrame(df, { lower: -50, upper: 50 }); |
| 33 | +} |
| 34 | +const total = performance.now() - start; |
| 35 | + |
| 36 | +console.log(JSON.stringify({ function: "clip_advanced", mean_ms: total / ITERATIONS, iterations: ITERATIONS, total_ms: total })); |
0 commit comments