Skip to content

Commit 94a76b2

Browse files
Iteration 163: 6 new benchmark pairs (514 total, +1 vs best 513)
Added: series_to_array, dataframe_has_col_get, series_var_method, series_min_max_method, dataframe_var_method, dataframe_median_method. Run: https://github.com/githubnext/tsessebe/actions/runs/24583783780 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 4edd601 commit 94a76b2

12 files changed

Lines changed: 339 additions & 0 deletions
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
"""Benchmark: DataFrame column presence and access (.keys(), [], __getitem__) on 100k-row DataFrame."""
2+
import json, time
3+
import pandas as pd
4+
5+
SIZE = 100_000
6+
WARMUP = 10
7+
ITERATIONS = 100
8+
9+
df = pd.DataFrame({"a": list(range(SIZE)), "b": [i * 2.0 for i in range(SIZE)], "c": [str(i) for i in range(SIZE)]})
10+
11+
for _ in range(WARMUP):
12+
"a" in df.columns
13+
df["b"]
14+
df.get("c")
15+
16+
times = []
17+
for _ in range(ITERATIONS):
18+
t0 = time.perf_counter()
19+
"a" in df.columns
20+
df["b"]
21+
df.get("c")
22+
times.append((time.perf_counter() - t0) * 1000)
23+
24+
total = sum(times)
25+
print(json.dumps({"function": "dataframe_has_col_get", "mean_ms": round(total / ITERATIONS, 3), "iterations": ITERATIONS, "total_ms": round(total, 3)}))
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
"""Benchmark: DataFrame.median() — column-wise median on 100k-row DataFrame."""
2+
import json, time
3+
import pandas as pd
4+
5+
SIZE = 100_000
6+
WARMUP = 5
7+
ITERATIONS = 50
8+
9+
df = pd.DataFrame({"a": [i * 1.1 for i in range(SIZE)], "b": [i * 2.2 for i in range(SIZE)], "c": [i * 3.3 for i in range(SIZE)]})
10+
11+
for _ in range(WARMUP): df.median()
12+
13+
times = []
14+
for _ in range(ITERATIONS):
15+
t0 = time.perf_counter()
16+
df.median()
17+
times.append((time.perf_counter() - t0) * 1000)
18+
19+
total = sum(times)
20+
print(json.dumps({"function": "dataframe_median_method", "mean_ms": round(total / ITERATIONS, 3), "iterations": ITERATIONS, "total_ms": round(total, 3)}))
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
"""Benchmark: DataFrame.var() — column-wise variance on 100k-row DataFrame."""
2+
import json, time
3+
import pandas as pd
4+
5+
SIZE = 100_000
6+
WARMUP = 10
7+
ITERATIONS = 100
8+
9+
df = pd.DataFrame({"a": [i * 1.1 for i in range(SIZE)], "b": [i * 2.2 for i in range(SIZE)], "c": [i * 3.3 for i in range(SIZE)]})
10+
11+
for _ in range(WARMUP): df.var()
12+
13+
times = []
14+
for _ in range(ITERATIONS):
15+
t0 = time.perf_counter()
16+
df.var()
17+
times.append((time.perf_counter() - t0) * 1000)
18+
19+
total = sum(times)
20+
print(json.dumps({"function": "dataframe_var_method", "mean_ms": round(total / ITERATIONS, 3), "iterations": ITERATIONS, "total_ms": round(total, 3)}))
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"""Benchmark: Series.min() and .max() — min/max on 100k numeric Series."""
2+
import json, time
3+
import math
4+
import pandas as pd
5+
6+
SIZE = 100_000
7+
WARMUP = 10
8+
ITERATIONS = 100
9+
10+
s = pd.Series([math.sin(i) * 1000 for i in range(SIZE)])
11+
12+
for _ in range(WARMUP):
13+
s.min()
14+
s.max()
15+
16+
times = []
17+
for _ in range(ITERATIONS):
18+
t0 = time.perf_counter()
19+
s.min()
20+
s.max()
21+
times.append((time.perf_counter() - t0) * 1000)
22+
23+
total = sum(times)
24+
print(json.dumps({"function": "series_min_max_method", "mean_ms": round(total / ITERATIONS, 3), "iterations": ITERATIONS, "total_ms": round(total, 3)}))
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"""Benchmark: Series.to_numpy() and .tolist() — convert 100k-element Series to plain arrays."""
2+
import json, time
3+
import pandas as pd
4+
import numpy as np
5+
6+
SIZE = 100_000
7+
WARMUP = 10
8+
ITERATIONS = 100
9+
10+
s = pd.Series([i * 2.5 for i in range(SIZE)])
11+
12+
for _ in range(WARMUP):
13+
s.to_numpy()
14+
s.tolist()
15+
16+
times = []
17+
for _ in range(ITERATIONS):
18+
t0 = time.perf_counter()
19+
s.to_numpy()
20+
s.tolist()
21+
times.append((time.perf_counter() - t0) * 1000)
22+
23+
total = sum(times)
24+
print(json.dumps({"function": "series_to_array", "mean_ms": round(total / ITERATIONS, 3), "iterations": ITERATIONS, "total_ms": round(total, 3)}))
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
"""Benchmark: Series.var() — variance on 100k numeric Series."""
2+
import json, time
3+
import pandas as pd
4+
5+
SIZE = 100_000
6+
WARMUP = 10
7+
ITERATIONS = 100
8+
9+
s = pd.Series([i * 0.5 for i in range(SIZE)])
10+
11+
for _ in range(WARMUP): s.var()
12+
13+
times = []
14+
for _ in range(ITERATIONS):
15+
t0 = time.perf_counter()
16+
s.var()
17+
times.append((time.perf_counter() - t0) * 1000)
18+
19+
total = sum(times)
20+
print(json.dumps({"function": "series_var_method", "mean_ms": round(total / ITERATIONS, 3), "iterations": ITERATIONS, "total_ms": round(total, 3)}))
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* Benchmark: DataFrame.has(), .col(), .get() — column presence and access on 100k-row DataFrame.
3+
* Outputs JSON: {"function": "dataframe_has_col_get", "mean_ms": ..., "iterations": ..., "total_ms": ...}
4+
*/
5+
import { DataFrame } from "../../src/index.ts";
6+
7+
const SIZE = 100_000;
8+
const WARMUP = 10;
9+
const ITERATIONS = 100;
10+
11+
const df = new DataFrame({
12+
a: Array.from({ length: SIZE }, (_, i) => i),
13+
b: Array.from({ length: SIZE }, (_, i) => i * 2.0),
14+
c: Array.from({ length: SIZE }, (_, i) => String(i)),
15+
});
16+
17+
for (let i = 0; i < WARMUP; i++) {
18+
df.has("a");
19+
df.col("b");
20+
df.get("c");
21+
}
22+
23+
const times: number[] = [];
24+
for (let i = 0; i < ITERATIONS; i++) {
25+
const t0 = performance.now();
26+
df.has("a");
27+
df.col("b");
28+
df.get("c");
29+
times.push(performance.now() - t0);
30+
}
31+
32+
const total = times.reduce((a, b) => a + b, 0);
33+
console.log(
34+
JSON.stringify({
35+
function: "dataframe_has_col_get",
36+
mean_ms: Math.round((total / ITERATIONS) * 1000) / 1000,
37+
iterations: ITERATIONS,
38+
total_ms: Math.round(total * 1000) / 1000,
39+
}),
40+
);
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* Benchmark: DataFrame.median() — column-wise median on 100k-row DataFrame.
3+
* Outputs JSON: {"function": "dataframe_median_method", "mean_ms": ..., "iterations": ..., "total_ms": ...}
4+
*/
5+
import { DataFrame } from "../../src/index.ts";
6+
7+
const SIZE = 100_000;
8+
const WARMUP = 5;
9+
const ITERATIONS = 50;
10+
11+
const df = new DataFrame({
12+
a: Array.from({ length: SIZE }, (_, i) => i * 1.1),
13+
b: Array.from({ length: SIZE }, (_, i) => i * 2.2),
14+
c: Array.from({ length: SIZE }, (_, i) => i * 3.3),
15+
});
16+
17+
for (let i = 0; i < WARMUP; i++) df.median();
18+
19+
const times: number[] = [];
20+
for (let i = 0; i < ITERATIONS; i++) {
21+
const t0 = performance.now();
22+
df.median();
23+
times.push(performance.now() - t0);
24+
}
25+
26+
const total = times.reduce((a, b) => a + b, 0);
27+
console.log(
28+
JSON.stringify({
29+
function: "dataframe_median_method",
30+
mean_ms: Math.round((total / ITERATIONS) * 1000) / 1000,
31+
iterations: ITERATIONS,
32+
total_ms: Math.round(total * 1000) / 1000,
33+
}),
34+
);
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* Benchmark: DataFrame.var() — column-wise variance on 100k-row DataFrame.
3+
* Outputs JSON: {"function": "dataframe_var_method", "mean_ms": ..., "iterations": ..., "total_ms": ...}
4+
*/
5+
import { DataFrame } from "../../src/index.ts";
6+
7+
const SIZE = 100_000;
8+
const WARMUP = 10;
9+
const ITERATIONS = 100;
10+
11+
const df = new DataFrame({
12+
a: Array.from({ length: SIZE }, (_, i) => i * 1.1),
13+
b: Array.from({ length: SIZE }, (_, i) => i * 2.2),
14+
c: Array.from({ length: SIZE }, (_, i) => i * 3.3),
15+
});
16+
17+
for (let i = 0; i < WARMUP; i++) df.var();
18+
19+
const times: number[] = [];
20+
for (let i = 0; i < ITERATIONS; i++) {
21+
const t0 = performance.now();
22+
df.var();
23+
times.push(performance.now() - t0);
24+
}
25+
26+
const total = times.reduce((a, b) => a + b, 0);
27+
console.log(
28+
JSON.stringify({
29+
function: "dataframe_var_method",
30+
mean_ms: Math.round((total / ITERATIONS) * 1000) / 1000,
31+
iterations: ITERATIONS,
32+
total_ms: Math.round(total * 1000) / 1000,
33+
}),
34+
);
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* Benchmark: Series.min() and .max() — min/max on 100k numeric Series.
3+
* Outputs JSON: {"function": "series_min_max_method", "mean_ms": ..., "iterations": ..., "total_ms": ...}
4+
*/
5+
import { Series } from "../../src/index.ts";
6+
7+
const SIZE = 100_000;
8+
const WARMUP = 10;
9+
const ITERATIONS = 100;
10+
11+
const s = new Series({ data: Array.from({ length: SIZE }, (_, i) => Math.sin(i) * 1000) });
12+
13+
for (let i = 0; i < WARMUP; i++) {
14+
s.min();
15+
s.max();
16+
}
17+
18+
const times: number[] = [];
19+
for (let i = 0; i < ITERATIONS; i++) {
20+
const t0 = performance.now();
21+
s.min();
22+
s.max();
23+
times.push(performance.now() - t0);
24+
}
25+
26+
const total = times.reduce((a, b) => a + b, 0);
27+
console.log(
28+
JSON.stringify({
29+
function: "series_min_max_method",
30+
mean_ms: Math.round((total / ITERATIONS) * 1000) / 1000,
31+
iterations: ITERATIONS,
32+
total_ms: Math.round(total * 1000) / 1000,
33+
}),
34+
);

0 commit comments

Comments
 (0)