Skip to content

Commit 3d8392a

Browse files
[Autoloop: perf-comparison] Iteration 380: add assert_equal benchmark pair
Adds assertSeriesEqual / assertFrameEqual / assertIndexEqual benchmarks mirroring pd.testing.assert_series_equal / assert_frame_equal / assert_index_equal. Metric: 724 → 725 benchmark pairs. Run: https://github.com/githubnext/tsb/actions/runs/28378441925 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 2b08a48 commit 3d8392a

2 files changed

Lines changed: 115 additions & 0 deletions

File tree

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
"""Benchmark: pd.testing.assert_series_equal / assert_frame_equal / assert_index_equal."""
2+
import json, time
3+
import numpy as np
4+
import pandas as pd
5+
6+
SIZE = 10_000
7+
WARMUP = 5
8+
ITERATIONS = 100
9+
10+
numeric_data = np.arange(SIZE, dtype=float) * 0.1
11+
string_data = [f"item_{i % 200}" for i in range(SIZE)]
12+
bool_data = np.arange(SIZE) % 2 == 0
13+
14+
s1 = pd.Series(numeric_data)
15+
s2 = pd.Series(numeric_data.copy())
16+
s_str1 = pd.Series(string_data)
17+
s_str2 = pd.Series(string_data.copy())
18+
19+
df1 = pd.DataFrame({"a": numeric_data, "b": string_data, "c": bool_data})
20+
df2 = pd.DataFrame({"a": numeric_data.copy(), "b": string_data.copy(), "c": bool_data.copy()})
21+
22+
idx1 = pd.Index(np.arange(SIZE))
23+
idx2 = pd.Index(np.arange(SIZE))
24+
25+
for _ in range(WARMUP):
26+
pd.testing.assert_series_equal(s1, s2)
27+
pd.testing.assert_series_equal(s_str1, s_str2)
28+
pd.testing.assert_frame_equal(df1, df2)
29+
pd.testing.assert_index_equal(idx1, idx2)
30+
31+
start = time.perf_counter()
32+
for _ in range(ITERATIONS):
33+
pd.testing.assert_series_equal(s1, s2)
34+
pd.testing.assert_series_equal(s_str1, s_str2)
35+
pd.testing.assert_frame_equal(df1, df2)
36+
pd.testing.assert_index_equal(idx1, idx2)
37+
total = (time.perf_counter() - start) * 1000
38+
39+
print(json.dumps({
40+
"function": "assert_equal",
41+
"mean_ms": total / ITERATIONS,
42+
"iterations": ITERATIONS,
43+
"total_ms": total,
44+
}))
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/**
2+
* Benchmark: assertSeriesEqual / assertFrameEqual / assertIndexEqual — testing utilities.
3+
*
4+
* Mirrors pandas.testing:
5+
* - pd.testing.assert_series_equal
6+
* - pd.testing.assert_frame_equal
7+
* - pd.testing.assert_index_equal
8+
*
9+
* Tests equality checks on 10k-row numeric and string data.
10+
* Outputs JSON: {"function": "assert_equal", "mean_ms": ..., "iterations": ..., "total_ms": ...}
11+
*/
12+
import {
13+
Series,
14+
DataFrame,
15+
Index,
16+
assertSeriesEqual,
17+
assertFrameEqual,
18+
assertIndexEqual,
19+
} from "../../src/index.ts";
20+
21+
const SIZE = 10_000;
22+
const WARMUP = 5;
23+
const ITERATIONS = 100;
24+
25+
const numericData = Array.from({ length: SIZE }, (_, i) => i * 0.1);
26+
const stringData = Array.from({ length: SIZE }, (_, i) => `item_${i % 200}`);
27+
const boolData = Array.from({ length: SIZE }, (_, i) => i % 2 === 0);
28+
29+
const s1 = new Series({ data: numericData });
30+
const s2 = new Series({ data: numericData });
31+
const sStr1 = new Series({ data: stringData });
32+
const sStr2 = new Series({ data: stringData });
33+
34+
const df1 = DataFrame.fromColumns({
35+
a: numericData,
36+
b: stringData,
37+
c: boolData,
38+
});
39+
const df2 = DataFrame.fromColumns({
40+
a: numericData,
41+
b: stringData,
42+
c: boolData,
43+
});
44+
45+
const idx1 = new Index(Array.from({ length: SIZE }, (_, i) => i));
46+
const idx2 = new Index(Array.from({ length: SIZE }, (_, i) => i));
47+
48+
for (let i = 0; i < WARMUP; i++) {
49+
assertSeriesEqual(s1, s2);
50+
assertSeriesEqual(sStr1, sStr2);
51+
assertFrameEqual(df1, df2);
52+
assertIndexEqual(idx1, idx2);
53+
}
54+
55+
const start = performance.now();
56+
for (let i = 0; i < ITERATIONS; i++) {
57+
assertSeriesEqual(s1, s2);
58+
assertSeriesEqual(sStr1, sStr2);
59+
assertFrameEqual(df1, df2);
60+
assertIndexEqual(idx1, idx2);
61+
}
62+
const total_ms = performance.now() - start;
63+
64+
console.log(
65+
JSON.stringify({
66+
function: "assert_equal",
67+
mean_ms: total_ms / ITERATIONS,
68+
iterations: ITERATIONS,
69+
total_ms,
70+
}),
71+
);

0 commit comments

Comments
 (0)