|
| 1 | +/** |
| 2 | + * Benchmark: insertColumn, popColumn, reorderColumns, moveColumn on a 10k-row DataFrame |
| 3 | + * |
| 4 | + * Mirrors pandas DataFrame.insert() and DataFrame.pop() operations. |
| 5 | + */ |
| 6 | +import { DataFrame, insertColumn, popColumn, reorderColumns, moveColumn } from "../../src/index.js"; |
| 7 | + |
| 8 | +const ROWS = 10_000; |
| 9 | +const WARMUP = 3; |
| 10 | +const ITERATIONS = 10; |
| 11 | + |
| 12 | +const data = Array.from({ length: ROWS }, (_, i) => i); |
| 13 | +const df = DataFrame.fromColumns({ a: data, b: data, c: data, d: data }); |
| 14 | +const extraCol = Array.from({ length: ROWS }, (_, i) => i * 2); |
| 15 | + |
| 16 | +for (let i = 0; i < WARMUP; i++) { |
| 17 | + const df2 = insertColumn(df, 2, "x", extraCol); |
| 18 | + popColumn(df2, "x"); |
| 19 | + reorderColumns(df, ["d", "c", "b", "a"]); |
| 20 | + moveColumn(df, "c", 0); |
| 21 | +} |
| 22 | + |
| 23 | +const start = performance.now(); |
| 24 | +for (let i = 0; i < ITERATIONS; i++) { |
| 25 | + const df2 = insertColumn(df, 2, "x", extraCol); |
| 26 | + popColumn(df2, "x"); |
| 27 | + reorderColumns(df, ["d", "c", "b", "a"]); |
| 28 | + moveColumn(df, "c", 0); |
| 29 | +} |
| 30 | +const total = performance.now() - start; |
| 31 | + |
| 32 | +console.log( |
| 33 | + JSON.stringify({ |
| 34 | + function: "insert_pop", |
| 35 | + mean_ms: total / ITERATIONS, |
| 36 | + iterations: ITERATIONS, |
| 37 | + total_ms: total, |
| 38 | + }), |
| 39 | +); |
0 commit comments