From c07f852cb4a8aa84f647aafa5f795ab42ce71d2c Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 1 May 2026 18:47:49 +0000 Subject: [PATCH] Iteration 301: Add xs, update, compare benchmark pairs Run: https://github.com/githubnext/tsessebe/actions/runs/25227439051 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- benchmarks/pandas/bench_compare.py | 28 ++++++++++++++++++++++++++++ benchmarks/pandas/bench_update.py | 30 ++++++++++++++++++++++++++++++ benchmarks/pandas/bench_xs.py | 24 ++++++++++++++++++++++++ benchmarks/tsb/bench_compare.ts | 30 ++++++++++++++++++++++++++++++ benchmarks/tsb/bench_update.ts | 29 +++++++++++++++++++++++++++++ benchmarks/tsb/bench_xs.ts | 30 ++++++++++++++++++++++++++++++ 6 files changed, 171 insertions(+) create mode 100644 benchmarks/pandas/bench_compare.py create mode 100644 benchmarks/pandas/bench_update.py create mode 100644 benchmarks/pandas/bench_xs.py create mode 100644 benchmarks/tsb/bench_compare.ts create mode 100644 benchmarks/tsb/bench_update.ts create mode 100644 benchmarks/tsb/bench_xs.ts diff --git a/benchmarks/pandas/bench_compare.py b/benchmarks/pandas/bench_compare.py new file mode 100644 index 00000000..6124844a --- /dev/null +++ b/benchmarks/pandas/bench_compare.py @@ -0,0 +1,28 @@ +import pandas as pd +import json +import time + +N = 100_000 +data = [i % 1000 for i in range(N)] +s = pd.Series(data, dtype=float) + +# Warm-up +for _ in range(20): + s.eq(500) + s.lt(300) + s.ge(700) + +iterations = 300 +start = time.perf_counter() +for _ in range(iterations): + s.eq(500) + s.lt(300) + s.ge(700) +total_ms = (time.perf_counter() - start) * 1000 + +print(json.dumps({ + "function": "compare", + "mean_ms": total_ms / iterations, + "iterations": iterations, + "total_ms": total_ms, +})) diff --git a/benchmarks/pandas/bench_update.py b/benchmarks/pandas/bench_update.py new file mode 100644 index 00000000..b4381027 --- /dev/null +++ b/benchmarks/pandas/bench_update.py @@ -0,0 +1,30 @@ +import pandas as pd +import numpy as np +import json +import time + +N = 100_000 +data = list(range(N)) +other_data = [i * 10 if i % 3 == 0 else None for i in range(N)] + +s = pd.Series(data, dtype=float) +o = pd.Series(other_data, dtype=float) + +# Warm-up +for _ in range(20): + sc = s.copy() + sc.update(o) + +iterations = 200 +start = time.perf_counter() +for _ in range(iterations): + sc = s.copy() + sc.update(o) +total_ms = (time.perf_counter() - start) * 1000 + +print(json.dumps({ + "function": "update", + "mean_ms": total_ms / iterations, + "iterations": iterations, + "total_ms": total_ms, +})) diff --git a/benchmarks/pandas/bench_xs.py b/benchmarks/pandas/bench_xs.py new file mode 100644 index 00000000..a6c3c6fc --- /dev/null +++ b/benchmarks/pandas/bench_xs.py @@ -0,0 +1,24 @@ +import pandas as pd +import json +import time + +N = 100_000 +index = [str(i) for i in range(N)] +df = pd.DataFrame({"a": range(N), "b": [i * 2 for i in range(N)]}, index=index) + +# Warm-up +for i in range(100): + df.xs("500") + +iterations = 10_000 +start = time.perf_counter() +for i in range(iterations): + df.xs(str(i % N)) +total_ms = (time.perf_counter() - start) * 1000 + +print(json.dumps({ + "function": "xs", + "mean_ms": total_ms / iterations, + "iterations": iterations, + "total_ms": total_ms, +})) diff --git a/benchmarks/tsb/bench_compare.ts b/benchmarks/tsb/bench_compare.ts new file mode 100644 index 00000000..b2d8caf1 --- /dev/null +++ b/benchmarks/tsb/bench_compare.ts @@ -0,0 +1,30 @@ +import { Series, seriesEq, seriesLt, seriesGe } from "../../src/index.ts"; + +const N = 100_000; +const data = Float64Array.from({ length: N }, (_, i) => i % 1000); +const s = new Series({ data }); + +// Warm-up +for (let i = 0; i < 20; i++) { + seriesEq(s, 500); + seriesLt(s, 300); + seriesGe(s, 700); +} + +const iterations = 300; +const start = performance.now(); +for (let i = 0; i < iterations; i++) { + seriesEq(s, 500); + seriesLt(s, 300); + seriesGe(s, 700); +} +const total_ms = performance.now() - start; + +console.log( + JSON.stringify({ + function: "compare", + mean_ms: total_ms / iterations, + iterations, + total_ms, + }), +); diff --git a/benchmarks/tsb/bench_update.ts b/benchmarks/tsb/bench_update.ts new file mode 100644 index 00000000..d06e560a --- /dev/null +++ b/benchmarks/tsb/bench_update.ts @@ -0,0 +1,29 @@ +import { Series, seriesUpdate } from "../../src/index.ts"; + +const N = 100_000; +const data = Float64Array.from({ length: N }, (_, i) => i); +const other = Float64Array.from({ length: N }, (_, i) => (i % 3 === 0 ? i * 10 : null as unknown as number)); + +const s = new Series({ data }); +const o = new Series({ data: other }); + +// Warm-up +for (let i = 0; i < 20; i++) { + seriesUpdate(s, o); +} + +const iterations = 200; +const start = performance.now(); +for (let i = 0; i < iterations; i++) { + seriesUpdate(s, o); +} +const total_ms = performance.now() - start; + +console.log( + JSON.stringify({ + function: "update", + mean_ms: total_ms / iterations, + iterations, + total_ms, + }), +); diff --git a/benchmarks/tsb/bench_xs.ts b/benchmarks/tsb/bench_xs.ts new file mode 100644 index 00000000..f28ab7a0 --- /dev/null +++ b/benchmarks/tsb/bench_xs.ts @@ -0,0 +1,30 @@ +import { DataFrame, xsDataFrame } from "../../src/index.ts"; + +const N = 100_000; +const rows = Array.from({ length: N }, (_, i) => i); +const a = Float64Array.from(rows); +const b = Float64Array.from(rows.map((x) => x * 2)); +const index = rows.map(String); + +const df = DataFrame.fromColumns({ a, b }, { index }); + +// Warm-up +for (let i = 0; i < 100; i++) { + xsDataFrame(df, "500"); +} + +const iterations = 10_000; +const start = performance.now(); +for (let i = 0; i < iterations; i++) { + xsDataFrame(df, String(i % N)); +} +const total_ms = performance.now() - start; + +console.log( + JSON.stringify({ + function: "xs", + mean_ms: total_ms / iterations, + iterations, + total_ms, + }), +);