Skip to content

Commit 634e5bf

Browse files
Iteration 242: 5 new benchmark pairs (589 total, +55 vs canonical 534)
Added standalone function benchmarks for uncovered functions: - dataframe_abs_fn: dataFrameAbs standalone (not .abs() method) - dataframe_round_fn: dataFrameRound standalone (not .round() method) - unstack_fn: unstack standalone function (not .unstack() method) - series_numeric_pipeline: abs → round → clip chain - dataframe_numeric_pipeline: abs → round → sign chain Plus cherry-picked 50 pairs from origin/autoloop/perf-comparison-8724e9f9. Total: 534 (canonical) + 55 new = 589 pairs. Run: https://github.com/githubnext/tsessebe/actions/runs/24641474300 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent e9271d9 commit 634e5bf

10 files changed

Lines changed: 396 additions & 0 deletions
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
"""
2+
Benchmark: dataFrameAbs standalone — absolute value on a 100k-row × 4-column DataFrame.
3+
Mirrors bench_dataframe_abs_fn.ts (uses df.abs() which is the pandas equivalent).
4+
Outputs JSON: {"function": "dataframe_abs_fn", "mean_ms": ..., "iterations": ..., "total_ms": ...}
5+
"""
6+
import json
7+
import time
8+
import numpy as np
9+
import pandas as pd
10+
11+
SIZE = 100_000
12+
WARMUP = 5
13+
ITERATIONS = 30
14+
15+
df = pd.DataFrame(
16+
{
17+
"a": [(i % 200) - 100 for i in range(SIZE)],
18+
"b": [np.sin(i * 0.01) * 100 for i in range(SIZE)],
19+
"c": [-i * 0.5 for i in range(SIZE)],
20+
"d": [(i % 50) - 25 for i in range(SIZE)],
21+
}
22+
)
23+
24+
for _ in range(WARMUP):
25+
df.abs()
26+
27+
start = time.perf_counter()
28+
for _ in range(ITERATIONS):
29+
df.abs()
30+
total = (time.perf_counter() - start) * 1000
31+
32+
print(
33+
json.dumps(
34+
{
35+
"function": "dataframe_abs_fn",
36+
"mean_ms": total / ITERATIONS,
37+
"iterations": ITERATIONS,
38+
"total_ms": total,
39+
}
40+
)
41+
)
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
"""
2+
Benchmark: DataFrame numeric pipeline — chain abs → round → sign on a 100k-row × 3-column DataFrame.
3+
Mirrors bench_dataframe_numeric_pipeline.ts.
4+
Outputs JSON: {"function": "dataframe_numeric_pipeline", "mean_ms": ..., "iterations": ..., "total_ms": ...}
5+
"""
6+
import json
7+
import time
8+
import math
9+
import numpy as np
10+
import pandas as pd
11+
12+
SIZE = 100_000
13+
WARMUP = 5
14+
ITERATIONS = 20
15+
16+
df = pd.DataFrame(
17+
{
18+
"a": [math.sin(i * 0.01) * 150 - 20 for i in range(SIZE)],
19+
"b": [math.cos(i * 0.02) * 80 for i in range(SIZE)],
20+
"c": [(i % 1000) * 0.123 - 50 for i in range(SIZE)],
21+
}
22+
)
23+
24+
for _ in range(WARMUP):
25+
a = df.abs()
26+
b = a.round(1)
27+
np.sign(b)
28+
29+
start = time.perf_counter()
30+
for _ in range(ITERATIONS):
31+
a = df.abs()
32+
b = a.round(1)
33+
np.sign(b)
34+
total = (time.perf_counter() - start) * 1000
35+
36+
print(
37+
json.dumps(
38+
{
39+
"function": "dataframe_numeric_pipeline",
40+
"mean_ms": total / ITERATIONS,
41+
"iterations": ITERATIONS,
42+
"total_ms": total,
43+
}
44+
)
45+
)
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
"""
2+
Benchmark: dataFrameRound standalone — round a 100k-row × 4-column DataFrame to 2 decimals.
3+
Mirrors bench_dataframe_round_fn.ts (uses df.round(2) which is the pandas equivalent).
4+
Outputs JSON: {"function": "dataframe_round_fn", "mean_ms": ..., "iterations": ..., "total_ms": ...}
5+
"""
6+
import json
7+
import time
8+
import math
9+
import pandas as pd
10+
11+
SIZE = 100_000
12+
WARMUP = 5
13+
ITERATIONS = 30
14+
15+
df = pd.DataFrame(
16+
{
17+
"a": [i * 0.123456 for i in range(SIZE)],
18+
"b": [math.sin(i * 0.01) * 99.9 for i in range(SIZE)],
19+
"c": [-i * 0.987654 for i in range(SIZE)],
20+
"d": [(i % 1000) * 3.14159 for i in range(SIZE)],
21+
}
22+
)
23+
24+
for _ in range(WARMUP):
25+
df.round(2)
26+
27+
start = time.perf_counter()
28+
for _ in range(ITERATIONS):
29+
df.round(2)
30+
total = (time.perf_counter() - start) * 1000
31+
32+
print(
33+
json.dumps(
34+
{
35+
"function": "dataframe_round_fn",
36+
"mean_ms": total / ITERATIONS,
37+
"iterations": ITERATIONS,
38+
"total_ms": total,
39+
}
40+
)
41+
)
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
"""
2+
Benchmark: Series numeric pipeline — chain abs → round → clip on a 100k-element Series.
3+
Mirrors bench_series_numeric_pipeline.ts.
4+
Outputs JSON: {"function": "series_numeric_pipeline", "mean_ms": ..., "iterations": ..., "total_ms": ...}
5+
"""
6+
import json
7+
import time
8+
import math
9+
import pandas as pd
10+
11+
SIZE = 100_000
12+
WARMUP = 5
13+
ITERATIONS = 30
14+
15+
s = pd.Series([math.sin(i * 0.01) * 150 - 20 for i in range(SIZE)])
16+
17+
for _ in range(WARMUP):
18+
a = s.abs()
19+
b = a.round(2)
20+
b.clip(lower=0, upper=100)
21+
22+
start = time.perf_counter()
23+
for _ in range(ITERATIONS):
24+
a = s.abs()
25+
b = a.round(2)
26+
b.clip(lower=0, upper=100)
27+
total = (time.perf_counter() - start) * 1000
28+
29+
print(
30+
json.dumps(
31+
{
32+
"function": "series_numeric_pipeline",
33+
"mean_ms": total / ITERATIONS,
34+
"iterations": ITERATIONS,
35+
"total_ms": total,
36+
}
37+
)
38+
)
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
"""
2+
Benchmark: unstack standalone — pivot innermost MultiIndex level to columns using s.unstack().
3+
Mirrors bench_unstack_fn.ts.
4+
Outputs JSON: {"function": "unstack_fn", "mean_ms": ..., "iterations": ..., "total_ms": ...}
5+
"""
6+
import json
7+
import time
8+
import pandas as pd
9+
10+
ROWS = 500
11+
COLS = 10
12+
WARMUP = 5
13+
ITERATIONS = 50
14+
15+
data = [i * 1.0 for i in range(ROWS * COLS)]
16+
index = pd.MultiIndex.from_tuples(
17+
[(i // COLS, i % COLS) for i in range(ROWS * COLS)]
18+
)
19+
s = pd.Series(data, index=index)
20+
21+
for _ in range(WARMUP):
22+
s.unstack()
23+
24+
times = []
25+
for _ in range(ITERATIONS):
26+
t0 = time.perf_counter()
27+
s.unstack()
28+
times.append((time.perf_counter() - t0) * 1000)
29+
30+
total_ms = sum(times)
31+
mean_ms = total_ms / len(times)
32+
33+
print(
34+
json.dumps(
35+
{
36+
"function": "unstack_fn",
37+
"mean_ms": mean_ms,
38+
"iterations": ITERATIONS,
39+
"total_ms": total_ms,
40+
}
41+
)
42+
)
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* Benchmark: dataFrameAbs standalone — absolute value on a 100k-row × 4-column DataFrame.
3+
* Uses the exported dataFrameAbs function (not the .abs() method).
4+
* Outputs JSON: {"function": "dataframe_abs_fn", "mean_ms": ..., "iterations": ..., "total_ms": ...}
5+
*/
6+
import { DataFrame, dataFrameAbs } from "../../src/index.ts";
7+
8+
const SIZE = 100_000;
9+
const WARMUP = 5;
10+
const ITERATIONS = 30;
11+
12+
const df = DataFrame.fromColumns({
13+
a: Array.from({ length: SIZE }, (_, i) => (i % 200) - 100),
14+
b: Array.from({ length: SIZE }, (_, i) => Math.sin(i * 0.01) * 100),
15+
c: Array.from({ length: SIZE }, (_, i) => -i * 0.5),
16+
d: Array.from({ length: SIZE }, (_, i) => (i % 50) - 25),
17+
});
18+
19+
for (let i = 0; i < WARMUP; i++) {
20+
dataFrameAbs(df);
21+
}
22+
23+
const start = performance.now();
24+
for (let i = 0; i < ITERATIONS; i++) {
25+
dataFrameAbs(df);
26+
}
27+
const total = performance.now() - start;
28+
29+
console.log(
30+
JSON.stringify({
31+
function: "dataframe_abs_fn",
32+
mean_ms: total / ITERATIONS,
33+
iterations: ITERATIONS,
34+
total_ms: total,
35+
}),
36+
);
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
* Benchmark: DataFrame numeric pipeline — chain abs → round → sign on a 100k-row × 3-column DataFrame.
3+
* Tests a realistic sequence of standalone DataFrame numeric operations.
4+
* Outputs JSON: {"function": "dataframe_numeric_pipeline", "mean_ms": ..., "iterations": ..., "total_ms": ...}
5+
*/
6+
import { DataFrame, dataFrameAbs, dataFrameRound, dataFrameSign } from "../../src/index.ts";
7+
8+
const SIZE = 100_000;
9+
const WARMUP = 5;
10+
const ITERATIONS = 20;
11+
12+
const df = DataFrame.fromColumns({
13+
a: Array.from({ length: SIZE }, (_, i) => Math.sin(i * 0.01) * 150 - 20),
14+
b: Array.from({ length: SIZE }, (_, i) => Math.cos(i * 0.02) * 80),
15+
c: Array.from({ length: SIZE }, (_, i) => (i % 1000) * 0.123 - 50),
16+
});
17+
18+
for (let i = 0; i < WARMUP; i++) {
19+
const a = dataFrameAbs(df);
20+
const b = dataFrameRound(a, { decimals: 1 });
21+
dataFrameSign(b);
22+
}
23+
24+
const start = performance.now();
25+
for (let i = 0; i < ITERATIONS; i++) {
26+
const a = dataFrameAbs(df);
27+
const b = dataFrameRound(a, { decimals: 1 });
28+
dataFrameSign(b);
29+
}
30+
const total = performance.now() - start;
31+
32+
console.log(
33+
JSON.stringify({
34+
function: "dataframe_numeric_pipeline",
35+
mean_ms: total / ITERATIONS,
36+
iterations: ITERATIONS,
37+
total_ms: total,
38+
}),
39+
);
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* Benchmark: dataFrameRound standalone — round a 100k-row × 4-column DataFrame to 2 decimals.
3+
* Uses the exported dataFrameRound function (not the .round() method).
4+
* Outputs JSON: {"function": "dataframe_round_fn", "mean_ms": ..., "iterations": ..., "total_ms": ...}
5+
*/
6+
import { DataFrame, dataFrameRound } from "../../src/index.ts";
7+
8+
const SIZE = 100_000;
9+
const WARMUP = 5;
10+
const ITERATIONS = 30;
11+
12+
const df = DataFrame.fromColumns({
13+
a: Array.from({ length: SIZE }, (_, i) => i * 0.123456),
14+
b: Array.from({ length: SIZE }, (_, i) => Math.sin(i * 0.01) * 99.9),
15+
c: Array.from({ length: SIZE }, (_, i) => -i * 0.987654),
16+
d: Array.from({ length: SIZE }, (_, i) => (i % 1000) * 3.14159),
17+
});
18+
19+
for (let i = 0; i < WARMUP; i++) {
20+
dataFrameRound(df, { decimals: 2 });
21+
}
22+
23+
const start = performance.now();
24+
for (let i = 0; i < ITERATIONS; i++) {
25+
dataFrameRound(df, { decimals: 2 });
26+
}
27+
const total = performance.now() - start;
28+
29+
console.log(
30+
JSON.stringify({
31+
function: "dataframe_round_fn",
32+
mean_ms: total / ITERATIONS,
33+
iterations: ITERATIONS,
34+
total_ms: total,
35+
}),
36+
);
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* Benchmark: Series numeric pipeline — chain abs → round → clip on a 100k-element Series.
3+
* Tests a realistic sequence of standalone numeric operations.
4+
* Outputs JSON: {"function": "series_numeric_pipeline", "mean_ms": ..., "iterations": ..., "total_ms": ...}
5+
*/
6+
import { Series, seriesAbs, seriesRound, clipSeriesWithBounds } from "../../src/index.ts";
7+
8+
const SIZE = 100_000;
9+
const WARMUP = 5;
10+
const ITERATIONS = 30;
11+
12+
const s = new Series({
13+
data: Array.from({ length: SIZE }, (_, i) => Math.sin(i * 0.01) * 150 - 20),
14+
});
15+
16+
for (let i = 0; i < WARMUP; i++) {
17+
const a = seriesAbs(s);
18+
const b = seriesRound(a, { decimals: 2 });
19+
clipSeriesWithBounds(b, { lower: 0, upper: 100 });
20+
}
21+
22+
const start = performance.now();
23+
for (let i = 0; i < ITERATIONS; i++) {
24+
const a = seriesAbs(s);
25+
const b = seriesRound(a, { decimals: 2 });
26+
clipSeriesWithBounds(b, { lower: 0, upper: 100 });
27+
}
28+
const total = performance.now() - start;
29+
30+
console.log(
31+
JSON.stringify({
32+
function: "series_numeric_pipeline",
33+
mean_ms: total / ITERATIONS,
34+
iterations: ITERATIONS,
35+
total_ms: total,
36+
}),
37+
);

0 commit comments

Comments
 (0)