From b86b87560acb71435c145c7b54d9ea4d51539b64 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 13 Apr 2026 20:45:35 +0000 Subject: [PATCH] Iteration 45: Add 11 benchmark pairs (melt, rolling_std, rolling_sum, expanding_mean, zscore, to_json, dataframe_corr, min_max_normalize, series_rank, series_nlargest, pearson_corr) Run: https://github.com/githubnext/tsessebe/actions/runs/24365226689 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- benchmarks/pandas/bench_dataframe_corr.py | 29 +++++++++ benchmarks/pandas/bench_expanding_mean.py | 26 ++++++++ benchmarks/pandas/bench_melt.py | 30 +++++++++ benchmarks/pandas/bench_min_max_normalize.py | 29 +++++++++ benchmarks/pandas/bench_pearson_corr.py | 26 ++++++++ benchmarks/pandas/bench_rolling_std.py | 26 ++++++++ benchmarks/pandas/bench_rolling_sum.py | 26 ++++++++ benchmarks/pandas/bench_series_nlargest.py | 26 ++++++++ benchmarks/pandas/bench_series_rank.py | 26 ++++++++ benchmarks/pandas/bench_to_json.py | 28 ++++++++ benchmarks/pandas/bench_zscore.py | 31 +++++++++ benchmarks/results.json | 68 +++++++++++++++++++- benchmarks/tsb/bench_dataframe_corr.ts | 32 +++++++++ benchmarks/tsb/bench_expanding_mean.ts | 30 +++++++++ benchmarks/tsb/bench_melt.ts | 33 ++++++++++ benchmarks/tsb/bench_min_max_normalize.ts | 30 +++++++++ benchmarks/tsb/bench_pearson_corr.ts | 32 +++++++++ benchmarks/tsb/bench_rolling_std.ts | 30 +++++++++ benchmarks/tsb/bench_rolling_sum.ts | 30 +++++++++ benchmarks/tsb/bench_series_nlargest.ts | 30 +++++++++ benchmarks/tsb/bench_series_rank.ts | 30 +++++++++ benchmarks/tsb/bench_to_json.ts | 31 +++++++++ benchmarks/tsb/bench_zscore.ts | 30 +++++++++ 23 files changed, 708 insertions(+), 1 deletion(-) create mode 100644 benchmarks/pandas/bench_dataframe_corr.py create mode 100644 benchmarks/pandas/bench_expanding_mean.py create mode 100644 benchmarks/pandas/bench_melt.py create mode 100644 benchmarks/pandas/bench_min_max_normalize.py create mode 100644 benchmarks/pandas/bench_pearson_corr.py create mode 100644 benchmarks/pandas/bench_rolling_std.py create mode 100644 benchmarks/pandas/bench_rolling_sum.py create mode 100644 benchmarks/pandas/bench_series_nlargest.py create mode 100644 benchmarks/pandas/bench_series_rank.py create mode 100644 benchmarks/pandas/bench_to_json.py create mode 100644 benchmarks/pandas/bench_zscore.py create mode 100644 benchmarks/tsb/bench_dataframe_corr.ts create mode 100644 benchmarks/tsb/bench_expanding_mean.ts create mode 100644 benchmarks/tsb/bench_melt.ts create mode 100644 benchmarks/tsb/bench_min_max_normalize.ts create mode 100644 benchmarks/tsb/bench_pearson_corr.ts create mode 100644 benchmarks/tsb/bench_rolling_std.ts create mode 100644 benchmarks/tsb/bench_rolling_sum.ts create mode 100644 benchmarks/tsb/bench_series_nlargest.ts create mode 100644 benchmarks/tsb/bench_series_rank.ts create mode 100644 benchmarks/tsb/bench_to_json.ts create mode 100644 benchmarks/tsb/bench_zscore.ts diff --git a/benchmarks/pandas/bench_dataframe_corr.py b/benchmarks/pandas/bench_dataframe_corr.py new file mode 100644 index 00000000..030cc6de --- /dev/null +++ b/benchmarks/pandas/bench_dataframe_corr.py @@ -0,0 +1,29 @@ +"""Benchmark: DataFrame.corr — pairwise Pearson correlation on a 10k-row DataFrame""" +import json, time +import numpy as np +import pandas as pd + +ROWS = 10_000 +WARMUP = 3 +ITERATIONS = 10 + +df = pd.DataFrame({ + "a": np.sin(np.arange(ROWS) * 0.01), + "b": np.cos(np.arange(ROWS) * 0.01), + "c": np.arange(ROWS, dtype=np.float64) * 0.001, +}) + +for _ in range(WARMUP): + df.corr() + +start = time.perf_counter() +for _ in range(ITERATIONS): + df.corr() +total = (time.perf_counter() - start) * 1000 + +print(json.dumps({ + "function": "dataframe_corr", + "mean_ms": total / ITERATIONS, + "iterations": ITERATIONS, + "total_ms": total, +})) diff --git a/benchmarks/pandas/bench_expanding_mean.py b/benchmarks/pandas/bench_expanding_mean.py new file mode 100644 index 00000000..7bc07538 --- /dev/null +++ b/benchmarks/pandas/bench_expanding_mean.py @@ -0,0 +1,26 @@ +"""Benchmark: expanding mean on 100k-element Series""" +import json, time +import numpy as np +import pandas as pd + +ROWS = 100_000 +WARMUP = 3 +ITERATIONS = 10 + +data = np.cos(np.arange(ROWS) * 0.01) +s = pd.Series(data) + +for _ in range(WARMUP): + s.expanding(1).mean() + +start = time.perf_counter() +for _ in range(ITERATIONS): + s.expanding(1).mean() +total = (time.perf_counter() - start) * 1000 + +print(json.dumps({ + "function": "expanding_mean", + "mean_ms": total / ITERATIONS, + "iterations": ITERATIONS, + "total_ms": total, +})) diff --git a/benchmarks/pandas/bench_melt.py b/benchmarks/pandas/bench_melt.py new file mode 100644 index 00000000..c6f2598a --- /dev/null +++ b/benchmarks/pandas/bench_melt.py @@ -0,0 +1,30 @@ +"""Benchmark: melt — unpivot a 10k-row DataFrame with 4 value columns""" +import json, time +import numpy as np +import pandas as pd + +ROWS = 10_000 +WARMUP = 3 +ITERATIONS = 10 + +df = pd.DataFrame({ + "id": np.arange(ROWS), + "a": np.arange(ROWS, dtype=np.float64) * 1.1, + "b": np.arange(ROWS, dtype=np.float64) * 2.2, + "c": np.arange(ROWS, dtype=np.float64) * 3.3, +}) + +for _ in range(WARMUP): + pd.melt(df, id_vars=["id"], value_vars=["a", "b", "c"]) + +start = time.perf_counter() +for _ in range(ITERATIONS): + pd.melt(df, id_vars=["id"], value_vars=["a", "b", "c"]) +total = (time.perf_counter() - start) * 1000 + +print(json.dumps({ + "function": "melt", + "mean_ms": total / ITERATIONS, + "iterations": ITERATIONS, + "total_ms": total, +})) diff --git a/benchmarks/pandas/bench_min_max_normalize.py b/benchmarks/pandas/bench_min_max_normalize.py new file mode 100644 index 00000000..57877bcb --- /dev/null +++ b/benchmarks/pandas/bench_min_max_normalize.py @@ -0,0 +1,29 @@ +"""Benchmark: min-max normalization — scale a 100k-element Series to [0, 1]""" +import json, time +import numpy as np +import pandas as pd + +ROWS = 100_000 +WARMUP = 3 +ITERATIONS = 10 + +data = np.arange(ROWS, dtype=np.float64) * 3.7 - 50_000 +s = pd.Series(data) + +def min_max_normalize(s): + return (s - s.min()) / (s.max() - s.min()) + +for _ in range(WARMUP): + min_max_normalize(s) + +start = time.perf_counter() +for _ in range(ITERATIONS): + min_max_normalize(s) +total = (time.perf_counter() - start) * 1000 + +print(json.dumps({ + "function": "min_max_normalize", + "mean_ms": total / ITERATIONS, + "iterations": ITERATIONS, + "total_ms": total, +})) diff --git a/benchmarks/pandas/bench_pearson_corr.py b/benchmarks/pandas/bench_pearson_corr.py new file mode 100644 index 00000000..12f04ec0 --- /dev/null +++ b/benchmarks/pandas/bench_pearson_corr.py @@ -0,0 +1,26 @@ +"""Benchmark: pearsonCorr — Pearson correlation between two 100k-element Series""" +import json, time +import numpy as np +import pandas as pd + +ROWS = 100_000 +WARMUP = 3 +ITERATIONS = 10 + +x = pd.Series(np.sin(np.arange(ROWS) * 0.01)) +y = pd.Series(np.sin(np.arange(ROWS) * 0.01 + 0.5)) + +for _ in range(WARMUP): + x.corr(y) + +start = time.perf_counter() +for _ in range(ITERATIONS): + x.corr(y) +total = (time.perf_counter() - start) * 1000 + +print(json.dumps({ + "function": "pearson_corr", + "mean_ms": total / ITERATIONS, + "iterations": ITERATIONS, + "total_ms": total, +})) diff --git a/benchmarks/pandas/bench_rolling_std.py b/benchmarks/pandas/bench_rolling_std.py new file mode 100644 index 00000000..11d2aaaa --- /dev/null +++ b/benchmarks/pandas/bench_rolling_std.py @@ -0,0 +1,26 @@ +"""Benchmark: rolling std with window=100 on 100k-element Series""" +import json, time +import numpy as np +import pandas as pd + +ROWS = 100_000 +WARMUP = 3 +ITERATIONS = 10 + +data = np.sin(np.arange(ROWS) * 0.01) +s = pd.Series(data) + +for _ in range(WARMUP): + s.rolling(100).std() + +start = time.perf_counter() +for _ in range(ITERATIONS): + s.rolling(100).std() +total = (time.perf_counter() - start) * 1000 + +print(json.dumps({ + "function": "rolling_std", + "mean_ms": total / ITERATIONS, + "iterations": ITERATIONS, + "total_ms": total, +})) diff --git a/benchmarks/pandas/bench_rolling_sum.py b/benchmarks/pandas/bench_rolling_sum.py new file mode 100644 index 00000000..5054ab09 --- /dev/null +++ b/benchmarks/pandas/bench_rolling_sum.py @@ -0,0 +1,26 @@ +"""Benchmark: rolling sum with window=100 on 100k-element Series""" +import json, time +import numpy as np +import pandas as pd + +ROWS = 100_000 +WARMUP = 3 +ITERATIONS = 10 + +data = np.arange(ROWS, dtype=np.float64) * 0.1 +s = pd.Series(data) + +for _ in range(WARMUP): + s.rolling(100).sum() + +start = time.perf_counter() +for _ in range(ITERATIONS): + s.rolling(100).sum() +total = (time.perf_counter() - start) * 1000 + +print(json.dumps({ + "function": "rolling_sum", + "mean_ms": total / ITERATIONS, + "iterations": ITERATIONS, + "total_ms": total, +})) diff --git a/benchmarks/pandas/bench_series_nlargest.py b/benchmarks/pandas/bench_series_nlargest.py new file mode 100644 index 00000000..b9dce8a4 --- /dev/null +++ b/benchmarks/pandas/bench_series_nlargest.py @@ -0,0 +1,26 @@ +"""Benchmark: Series.nlargest — top-100 elements from a 100k-element Series""" +import json, time +import numpy as np +import pandas as pd + +ROWS = 100_000 +WARMUP = 3 +ITERATIONS = 10 + +data = np.sin(np.arange(ROWS) * 0.007) * 500 + np.arange(ROWS) * 0.001 +s = pd.Series(data) + +for _ in range(WARMUP): + s.nlargest(100) + +start = time.perf_counter() +for _ in range(ITERATIONS): + s.nlargest(100) +total = (time.perf_counter() - start) * 1000 + +print(json.dumps({ + "function": "series_nlargest", + "mean_ms": total / ITERATIONS, + "iterations": ITERATIONS, + "total_ms": total, +})) diff --git a/benchmarks/pandas/bench_series_rank.py b/benchmarks/pandas/bench_series_rank.py new file mode 100644 index 00000000..e0ef6d99 --- /dev/null +++ b/benchmarks/pandas/bench_series_rank.py @@ -0,0 +1,26 @@ +"""Benchmark: Series.rank — rank 100k elements""" +import json, time +import numpy as np +import pandas as pd + +ROWS = 100_000 +WARMUP = 3 +ITERATIONS = 10 + +data = np.sin(np.arange(ROWS) * 0.03) * 1000 +s = pd.Series(data) + +for _ in range(WARMUP): + s.rank() + +start = time.perf_counter() +for _ in range(ITERATIONS): + s.rank() +total = (time.perf_counter() - start) * 1000 + +print(json.dumps({ + "function": "series_rank", + "mean_ms": total / ITERATIONS, + "iterations": ITERATIONS, + "total_ms": total, +})) diff --git a/benchmarks/pandas/bench_to_json.py b/benchmarks/pandas/bench_to_json.py new file mode 100644 index 00000000..8176c978 --- /dev/null +++ b/benchmarks/pandas/bench_to_json.py @@ -0,0 +1,28 @@ +"""Benchmark: to_json — serialize a 10k-row DataFrame to JSON""" +import json, time +import numpy as np +import pandas as pd + +ROWS = 10_000 +WARMUP = 3 +ITERATIONS = 10 + +df = pd.DataFrame({ + "a": np.arange(ROWS, dtype=np.float64) * 1.5, + "b": np.arange(ROWS, dtype=np.float64) * 2.5, +}) + +for _ in range(WARMUP): + df.to_json(orient="records") + +start = time.perf_counter() +for _ in range(ITERATIONS): + df.to_json(orient="records") +total = (time.perf_counter() - start) * 1000 + +print(json.dumps({ + "function": "to_json", + "mean_ms": total / ITERATIONS, + "iterations": ITERATIONS, + "total_ms": total, +})) diff --git a/benchmarks/pandas/bench_zscore.py b/benchmarks/pandas/bench_zscore.py new file mode 100644 index 00000000..2059ac27 --- /dev/null +++ b/benchmarks/pandas/bench_zscore.py @@ -0,0 +1,31 @@ +"""Benchmark: zscore normalization on 100k-element Series""" +import json, time +import numpy as np +import pandas as pd +from scipy import stats as sp_stats + +ROWS = 100_000 +WARMUP = 3 +ITERATIONS = 10 + +rng = np.random.default_rng(42) +data = rng.random(ROWS) * 100 +s = pd.Series(data) + +def zscore_pandas(s): + return (s - s.mean()) / s.std() + +for _ in range(WARMUP): + zscore_pandas(s) + +start = time.perf_counter() +for _ in range(ITERATIONS): + zscore_pandas(s) +total = (time.perf_counter() - start) * 1000 + +print(json.dumps({ + "function": "zscore", + "mean_ms": total / ITERATIONS, + "iterations": ITERATIONS, + "total_ms": total, +})) diff --git a/benchmarks/results.json b/benchmarks/results.json index c883f334..f250d284 100644 --- a/benchmarks/results.json +++ b/benchmarks/results.json @@ -22,6 +22,12 @@ }, "ratio": null }, + { + "function": "dataframe_corr", + "tsb": null, + "pandas": null, + "ratio": null + }, { "function": "dataframe_creation", "tsb": null, @@ -99,6 +105,12 @@ }, "ratio": null }, + { + "function": "expanding_mean", + "tsb": null, + "pandas": null, + "ratio": null + }, { "function": "groupby_mean", "tsb": null, @@ -110,6 +122,12 @@ }, "ratio": null }, + { + "function": "melt", + "tsb": null, + "pandas": null, + "ratio": null + }, { "function": "merge", "tsb": null, @@ -121,6 +139,18 @@ }, "ratio": null }, + { + "function": "min_max_normalize", + "tsb": null, + "pandas": null, + "ratio": null + }, + { + "function": "pearson_corr", + "tsb": null, + "pandas": null, + "ratio": null + }, { "function": "pivot_table", "tsb": null, @@ -154,6 +184,18 @@ }, "ratio": null }, + { + "function": "rolling_std", + "tsb": null, + "pandas": null, + "ratio": null + }, + { + "function": "rolling_sum", + "tsb": null, + "pandas": null, + "ratio": null + }, { "function": "series_arithmetic", "tsb": null, @@ -198,6 +240,18 @@ }, "ratio": null }, + { + "function": "series_nlargest", + "tsb": null, + "pandas": null, + "ratio": null + }, + { + "function": "series_rank", + "tsb": null, + "pandas": null, + "ratio": null + }, { "function": "series_shift", "tsb": null, @@ -241,7 +295,19 @@ "total_ms": 92.12644899997713 }, "ratio": null + }, + { + "function": "to_json", + "tsb": null, + "pandas": null, + "ratio": null + }, + { + "function": "zscore", + "tsb": null, + "pandas": null, + "ratio": null } ], - "timestamp": "2026-04-12T15:46:00Z" + "timestamp": "2026-04-13T20:33:20Z" } \ No newline at end of file diff --git a/benchmarks/tsb/bench_dataframe_corr.ts b/benchmarks/tsb/bench_dataframe_corr.ts new file mode 100644 index 00000000..9ddbed6a --- /dev/null +++ b/benchmarks/tsb/bench_dataframe_corr.ts @@ -0,0 +1,32 @@ +/** + * Benchmark: dataFrameCorr — pairwise Pearson correlation on a 10k-row DataFrame + */ +import { DataFrame, dataFrameCorr } from "../../src/index.js"; + +const ROWS = 10_000; +const WARMUP = 3; +const ITERATIONS = 10; + +const a = Float64Array.from({ length: ROWS }, (_, i) => Math.sin(i * 0.01)); +const b = Float64Array.from({ length: ROWS }, (_, i) => Math.cos(i * 0.01)); +const c = Float64Array.from({ length: ROWS }, (_, i) => i * 0.001); +const df = new DataFrame({ a, b, c }); + +for (let i = 0; i < WARMUP; i++) { + dataFrameCorr(df); +} + +const start = performance.now(); +for (let i = 0; i < ITERATIONS; i++) { + dataFrameCorr(df); +} +const total = performance.now() - start; + +console.log( + JSON.stringify({ + function: "dataframe_corr", + mean_ms: total / ITERATIONS, + iterations: ITERATIONS, + total_ms: total, + }), +); diff --git a/benchmarks/tsb/bench_expanding_mean.ts b/benchmarks/tsb/bench_expanding_mean.ts new file mode 100644 index 00000000..1924ca51 --- /dev/null +++ b/benchmarks/tsb/bench_expanding_mean.ts @@ -0,0 +1,30 @@ +/** + * Benchmark: expanding mean on 100k-element Series + */ +import { Series } from "../../src/index.js"; + +const ROWS = 100_000; +const WARMUP = 3; +const ITERATIONS = 10; + +const data = Float64Array.from({ length: ROWS }, (_, i) => Math.cos(i * 0.01)); +const s = new Series(data); + +for (let i = 0; i < WARMUP; i++) { + s.expanding(1).mean(); +} + +const start = performance.now(); +for (let i = 0; i < ITERATIONS; i++) { + s.expanding(1).mean(); +} +const total = performance.now() - start; + +console.log( + JSON.stringify({ + function: "expanding_mean", + mean_ms: total / ITERATIONS, + iterations: ITERATIONS, + total_ms: total, + }), +); diff --git a/benchmarks/tsb/bench_melt.ts b/benchmarks/tsb/bench_melt.ts new file mode 100644 index 00000000..3f663edd --- /dev/null +++ b/benchmarks/tsb/bench_melt.ts @@ -0,0 +1,33 @@ +/** + * Benchmark: melt — unpivot a 10k-row DataFrame with 4 value columns + */ +import { DataFrame, melt } from "../../src/index.js"; + +const ROWS = 10_000; +const WARMUP = 3; +const ITERATIONS = 10; + +const id = Array.from({ length: ROWS }, (_, i) => i); +const a = Float64Array.from({ length: ROWS }, (_, i) => i * 1.1); +const b = Float64Array.from({ length: ROWS }, (_, i) => i * 2.2); +const c = Float64Array.from({ length: ROWS }, (_, i) => i * 3.3); +const df = new DataFrame({ id, a, b, c }); + +for (let i = 0; i < WARMUP; i++) { + melt(df, { idVars: ["id"], valueVars: ["a", "b", "c"] }); +} + +const start = performance.now(); +for (let i = 0; i < ITERATIONS; i++) { + melt(df, { idVars: ["id"], valueVars: ["a", "b", "c"] }); +} +const total = performance.now() - start; + +console.log( + JSON.stringify({ + function: "melt", + mean_ms: total / ITERATIONS, + iterations: ITERATIONS, + total_ms: total, + }), +); diff --git a/benchmarks/tsb/bench_min_max_normalize.ts b/benchmarks/tsb/bench_min_max_normalize.ts new file mode 100644 index 00000000..9c0f7e9c --- /dev/null +++ b/benchmarks/tsb/bench_min_max_normalize.ts @@ -0,0 +1,30 @@ +/** + * Benchmark: minMaxNormalize — scale a 100k-element Series to [0, 1] + */ +import { Series, minMaxNormalize } from "../../src/index.js"; + +const ROWS = 100_000; +const WARMUP = 3; +const ITERATIONS = 10; + +const data = Float64Array.from({ length: ROWS }, (_, i) => i * 3.7 - 50_000); +const s = new Series(data); + +for (let i = 0; i < WARMUP; i++) { + minMaxNormalize(s); +} + +const start = performance.now(); +for (let i = 0; i < ITERATIONS; i++) { + minMaxNormalize(s); +} +const total = performance.now() - start; + +console.log( + JSON.stringify({ + function: "min_max_normalize", + mean_ms: total / ITERATIONS, + iterations: ITERATIONS, + total_ms: total, + }), +); diff --git a/benchmarks/tsb/bench_pearson_corr.ts b/benchmarks/tsb/bench_pearson_corr.ts new file mode 100644 index 00000000..97900abe --- /dev/null +++ b/benchmarks/tsb/bench_pearson_corr.ts @@ -0,0 +1,32 @@ +/** + * Benchmark: pearsonCorr — Pearson correlation between two 100k-element Series + */ +import { Series, pearsonCorr } from "../../src/index.js"; + +const ROWS = 100_000; +const WARMUP = 3; +const ITERATIONS = 10; + +const x = Float64Array.from({ length: ROWS }, (_, i) => Math.sin(i * 0.01)); +const y = Float64Array.from({ length: ROWS }, (_, i) => Math.sin(i * 0.01 + 0.5)); +const sx = new Series(x); +const sy = new Series(y); + +for (let i = 0; i < WARMUP; i++) { + pearsonCorr(sx, sy); +} + +const start = performance.now(); +for (let i = 0; i < ITERATIONS; i++) { + pearsonCorr(sx, sy); +} +const total = performance.now() - start; + +console.log( + JSON.stringify({ + function: "pearson_corr", + mean_ms: total / ITERATIONS, + iterations: ITERATIONS, + total_ms: total, + }), +); diff --git a/benchmarks/tsb/bench_rolling_std.ts b/benchmarks/tsb/bench_rolling_std.ts new file mode 100644 index 00000000..8212773c --- /dev/null +++ b/benchmarks/tsb/bench_rolling_std.ts @@ -0,0 +1,30 @@ +/** + * Benchmark: rolling std with window=100 on 100k-element Series + */ +import { Series } from "../../src/index.js"; + +const ROWS = 100_000; +const WARMUP = 3; +const ITERATIONS = 10; + +const data = Float64Array.from({ length: ROWS }, (_, i) => Math.sin(i * 0.01)); +const s = new Series(data); + +for (let i = 0; i < WARMUP; i++) { + s.rolling(100).std(); +} + +const start = performance.now(); +for (let i = 0; i < ITERATIONS; i++) { + s.rolling(100).std(); +} +const total = performance.now() - start; + +console.log( + JSON.stringify({ + function: "rolling_std", + mean_ms: total / ITERATIONS, + iterations: ITERATIONS, + total_ms: total, + }), +); diff --git a/benchmarks/tsb/bench_rolling_sum.ts b/benchmarks/tsb/bench_rolling_sum.ts new file mode 100644 index 00000000..cbc7fad6 --- /dev/null +++ b/benchmarks/tsb/bench_rolling_sum.ts @@ -0,0 +1,30 @@ +/** + * Benchmark: rolling sum with window=100 on 100k-element Series + */ +import { Series } from "../../src/index.js"; + +const ROWS = 100_000; +const WARMUP = 3; +const ITERATIONS = 10; + +const data = Float64Array.from({ length: ROWS }, (_, i) => i * 0.1); +const s = new Series(data); + +for (let i = 0; i < WARMUP; i++) { + s.rolling(100).sum(); +} + +const start = performance.now(); +for (let i = 0; i < ITERATIONS; i++) { + s.rolling(100).sum(); +} +const total = performance.now() - start; + +console.log( + JSON.stringify({ + function: "rolling_sum", + mean_ms: total / ITERATIONS, + iterations: ITERATIONS, + total_ms: total, + }), +); diff --git a/benchmarks/tsb/bench_series_nlargest.ts b/benchmarks/tsb/bench_series_nlargest.ts new file mode 100644 index 00000000..bf98a502 --- /dev/null +++ b/benchmarks/tsb/bench_series_nlargest.ts @@ -0,0 +1,30 @@ +/** + * Benchmark: Series.nlargest — top-100 elements from a 100k-element Series + */ +import { Series } from "../../src/index.js"; + +const ROWS = 100_000; +const WARMUP = 3; +const ITERATIONS = 10; + +const data = Float64Array.from({ length: ROWS }, (_, i) => Math.sin(i * 0.007) * 500 + i * 0.001); +const s = new Series(data); + +for (let i = 0; i < WARMUP; i++) { + s.nlargest(100); +} + +const start = performance.now(); +for (let i = 0; i < ITERATIONS; i++) { + s.nlargest(100); +} +const total = performance.now() - start; + +console.log( + JSON.stringify({ + function: "series_nlargest", + mean_ms: total / ITERATIONS, + iterations: ITERATIONS, + total_ms: total, + }), +); diff --git a/benchmarks/tsb/bench_series_rank.ts b/benchmarks/tsb/bench_series_rank.ts new file mode 100644 index 00000000..f55421a5 --- /dev/null +++ b/benchmarks/tsb/bench_series_rank.ts @@ -0,0 +1,30 @@ +/** + * Benchmark: Series.rank — rank 100k elements + */ +import { Series } from "../../src/index.js"; + +const ROWS = 100_000; +const WARMUP = 3; +const ITERATIONS = 10; + +const data = Float64Array.from({ length: ROWS }, (_, i) => Math.sin(i * 0.03) * 1000); +const s = new Series(data); + +for (let i = 0; i < WARMUP; i++) { + s.rank(); +} + +const start = performance.now(); +for (let i = 0; i < ITERATIONS; i++) { + s.rank(); +} +const total = performance.now() - start; + +console.log( + JSON.stringify({ + function: "series_rank", + mean_ms: total / ITERATIONS, + iterations: ITERATIONS, + total_ms: total, + }), +); diff --git a/benchmarks/tsb/bench_to_json.ts b/benchmarks/tsb/bench_to_json.ts new file mode 100644 index 00000000..46466b1e --- /dev/null +++ b/benchmarks/tsb/bench_to_json.ts @@ -0,0 +1,31 @@ +/** + * Benchmark: toJson — serialize a 10k-row DataFrame to JSON + */ +import { DataFrame, toJson } from "../../src/index.js"; + +const ROWS = 10_000; +const WARMUP = 3; +const ITERATIONS = 10; + +const a = Float64Array.from({ length: ROWS }, (_, i) => i * 1.5); +const b = Float64Array.from({ length: ROWS }, (_, i) => i * 2.5); +const df = new DataFrame({ a, b }); + +for (let i = 0; i < WARMUP; i++) { + toJson(df); +} + +const start = performance.now(); +for (let i = 0; i < ITERATIONS; i++) { + toJson(df); +} +const total = performance.now() - start; + +console.log( + JSON.stringify({ + function: "to_json", + mean_ms: total / ITERATIONS, + iterations: ITERATIONS, + total_ms: total, + }), +); diff --git a/benchmarks/tsb/bench_zscore.ts b/benchmarks/tsb/bench_zscore.ts new file mode 100644 index 00000000..b2564503 --- /dev/null +++ b/benchmarks/tsb/bench_zscore.ts @@ -0,0 +1,30 @@ +/** + * Benchmark: zscore normalization on 100k-element Series + */ +import { Series, zscore } from "../../src/index.js"; + +const ROWS = 100_000; +const WARMUP = 3; +const ITERATIONS = 10; + +const data = Float64Array.from({ length: ROWS }, (_, i) => Math.random() * 100); +const s = new Series(data); + +for (let i = 0; i < WARMUP; i++) { + zscore(s); +} + +const start = performance.now(); +for (let i = 0; i < ITERATIONS; i++) { + zscore(s); +} +const total = performance.now() - start; + +console.log( + JSON.stringify({ + function: "zscore", + mean_ms: total / ITERATIONS, + iterations: ITERATIONS, + total_ms: total, + }), +);