Skip to content

Commit e3c731c

Browse files
Iteration 148: Add 6 benchmark pairs (468 total, +6 vs best 462)
Add benchmarks for standalone comparison, floordiv/mod/pow, drop-duplicates, nsmallest, and duplicated functions not yet covered as standalone imports: - series_standalone_compare: seriesEq/Ne/Lt/Gt/Le/Ge - dataframe_compare_lege: dataFrameLe/dataFrameGe - series_floordiv_standalone: seriesFloorDiv/seriesMod/seriesPow - drop_duplicates_fn: dropDuplicatesSeries/dropDuplicatesDataFrame - nsmallest_series_fn: nsmallestSeries - duplicated_fn: duplicatedSeries/duplicatedDataFrame Run: https://github.com/githubnext/tsessebe/actions/runs/24558253472 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent b854980 commit e3c731c

12 files changed

Lines changed: 429 additions & 0 deletions
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
"""
2+
Benchmark: DataFrame <= and >= element-wise comparisons on 100k-row DataFrame.
3+
Mirrors dataFrameLe / dataFrameGe standalone functions.
4+
Outputs JSON: {"function": "dataframe_compare_lege", "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 = 50
14+
15+
df = pd.DataFrame({
16+
"a": np.arange(SIZE),
17+
"b": np.arange(SIZE) * 2,
18+
"c": np.arange(SIZE) % 100,
19+
})
20+
21+
for _ in range(WARMUP):
22+
df.le(50)
23+
df.ge(50)
24+
25+
start = time.perf_counter()
26+
for _ in range(ITERATIONS):
27+
df.le(50)
28+
df.ge(50)
29+
total = (time.perf_counter() - start) * 1000
30+
31+
print(json.dumps({
32+
"function": "dataframe_compare_lege",
33+
"mean_ms": total / ITERATIONS,
34+
"iterations": ITERATIONS,
35+
"total_ms": total,
36+
}))
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
"""
2+
Benchmark: Series.drop_duplicates / DataFrame.drop_duplicates on 100k elements.
3+
Mirrors dropDuplicatesSeries / dropDuplicatesDataFrame standalone functions.
4+
Outputs JSON: {"function": "drop_duplicates_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 = 50
14+
15+
s = pd.Series(np.arange(SIZE) % 1000)
16+
df = pd.DataFrame({
17+
"a": np.arange(SIZE) % 1000,
18+
"b": np.arange(SIZE) % 500,
19+
})
20+
21+
for _ in range(WARMUP):
22+
s.drop_duplicates()
23+
df.drop_duplicates()
24+
25+
start = time.perf_counter()
26+
for _ in range(ITERATIONS):
27+
s.drop_duplicates()
28+
df.drop_duplicates()
29+
total = (time.perf_counter() - start) * 1000
30+
31+
print(json.dumps({
32+
"function": "drop_duplicates_fn",
33+
"mean_ms": total / ITERATIONS,
34+
"iterations": ITERATIONS,
35+
"total_ms": total,
36+
}))
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
"""
2+
Benchmark: Series.duplicated / DataFrame.duplicated on 100k elements.
3+
Mirrors duplicatedSeries / duplicatedDataFrame standalone functions.
4+
Outputs JSON: {"function": "duplicated_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 = 50
14+
15+
s = pd.Series(np.arange(SIZE) % 1000)
16+
df = pd.DataFrame({
17+
"a": np.arange(SIZE) % 1000,
18+
"b": np.arange(SIZE) % 500,
19+
})
20+
21+
for _ in range(WARMUP):
22+
s.duplicated()
23+
df.duplicated()
24+
25+
start = time.perf_counter()
26+
for _ in range(ITERATIONS):
27+
s.duplicated()
28+
df.duplicated()
29+
total = (time.perf_counter() - start) * 1000
30+
31+
print(json.dumps({
32+
"function": "duplicated_fn",
33+
"mean_ms": total / ITERATIONS,
34+
"iterations": ITERATIONS,
35+
"total_ms": total,
36+
}))
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
"""
2+
Benchmark: Series.nsmallest on 100k-element Series.
3+
Mirrors nsmallestSeries standalone function.
4+
Outputs JSON: {"function": "nsmallest_series_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 = 50
14+
15+
data = np.sin(np.arange(SIZE) * 0.01) * 1000
16+
s = pd.Series(data)
17+
18+
for _ in range(WARMUP):
19+
s.nsmallest(100)
20+
21+
start = time.perf_counter()
22+
for _ in range(ITERATIONS):
23+
s.nsmallest(100)
24+
total = (time.perf_counter() - start) * 1000
25+
26+
print(json.dumps({
27+
"function": "nsmallest_series_fn",
28+
"mean_ms": total / ITERATIONS,
29+
"iterations": ITERATIONS,
30+
"total_ms": total,
31+
}))
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
"""
2+
Benchmark: Series floordiv / mod / pow standalone functions on 100k Series.
3+
Mirrors seriesFloorDiv / seriesMod / seriesPow.
4+
Outputs JSON: {"function": "series_floordiv_standalone", "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 = 50
14+
15+
data = (np.arange(SIZE) % 1000) + 1
16+
s = pd.Series(data.astype(float))
17+
18+
for _ in range(WARMUP):
19+
s.floordiv(3)
20+
s.mod(7)
21+
s.pow(2)
22+
23+
start = time.perf_counter()
24+
for _ in range(ITERATIONS):
25+
s.floordiv(3)
26+
s.mod(7)
27+
s.pow(2)
28+
total = (time.perf_counter() - start) * 1000
29+
30+
print(json.dumps({
31+
"function": "series_floordiv_standalone",
32+
"mean_ms": total / ITERATIONS,
33+
"iterations": ITERATIONS,
34+
"total_ms": total,
35+
}))
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
"""
2+
Benchmark: standalone Series comparison operators (eq, ne, lt, gt, le, ge) on 100k Series.
3+
Mirrors seriesEq/Ne/Lt/Gt/Le/Ge standalone functions.
4+
Outputs JSON: {"function": "series_standalone_compare", "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 = 50
14+
15+
data = np.arange(SIZE) * 0.1
16+
s = pd.Series(data)
17+
threshold = SIZE * 0.05
18+
19+
for _ in range(WARMUP):
20+
s.eq(threshold)
21+
s.ne(threshold)
22+
s.lt(threshold)
23+
s.gt(threshold)
24+
s.le(threshold)
25+
s.ge(threshold)
26+
27+
start = time.perf_counter()
28+
for _ in range(ITERATIONS):
29+
s.eq(threshold)
30+
s.ne(threshold)
31+
s.lt(threshold)
32+
s.gt(threshold)
33+
s.le(threshold)
34+
s.ge(threshold)
35+
total = (time.perf_counter() - start) * 1000
36+
37+
print(json.dumps({
38+
"function": "series_standalone_compare",
39+
"mean_ms": total / ITERATIONS,
40+
"iterations": ITERATIONS,
41+
"total_ms": total,
42+
}))
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* Benchmark: dataFrameLe / dataFrameGe — less-than-or-equal and greater-than-or-equal standalone functions on 100k-row DataFrame.
3+
* Outputs JSON: {"function": "dataframe_compare_lege", "mean_ms": ..., "iterations": ..., "total_ms": ...}
4+
*/
5+
import { DataFrame, dataFrameLe, dataFrameGe } 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),
13+
b: Array.from({ length: SIZE }, (_, i) => i * 2),
14+
c: Array.from({ length: SIZE }, (_, i) => i % 100),
15+
});
16+
17+
for (let i = 0; i < WARMUP; i++) {
18+
dataFrameLe(df, 50);
19+
dataFrameGe(df, 50);
20+
}
21+
22+
const start = performance.now();
23+
for (let i = 0; i < ITERATIONS; i++) {
24+
dataFrameLe(df, 50);
25+
dataFrameGe(df, 50);
26+
}
27+
const total = performance.now() - start;
28+
29+
console.log(
30+
JSON.stringify({
31+
function: "dataframe_compare_lege",
32+
mean_ms: total / ITERATIONS,
33+
iterations: ITERATIONS,
34+
total_ms: total,
35+
}),
36+
);
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* Benchmark: dropDuplicatesSeries / dropDuplicatesDataFrame — standalone drop-duplicates on 100k elements.
3+
* Outputs JSON: {"function": "drop_duplicates_fn", "mean_ms": ..., "iterations": ..., "total_ms": ...}
4+
*/
5+
import { Series, DataFrame, dropDuplicatesSeries, dropDuplicatesDataFrame } from "../../src/index.ts";
6+
7+
const SIZE = 100_000;
8+
const WARMUP = 5;
9+
const ITERATIONS = 50;
10+
11+
const s = new Series({ data: Array.from({ length: SIZE }, (_, i) => i % 1000) });
12+
const df = new DataFrame({
13+
a: Array.from({ length: SIZE }, (_, i) => i % 1000),
14+
b: Array.from({ length: SIZE }, (_, i) => i % 500),
15+
});
16+
17+
for (let i = 0; i < WARMUP; i++) {
18+
dropDuplicatesSeries(s);
19+
dropDuplicatesDataFrame(df);
20+
}
21+
22+
const start = performance.now();
23+
for (let i = 0; i < ITERATIONS; i++) {
24+
dropDuplicatesSeries(s);
25+
dropDuplicatesDataFrame(df);
26+
}
27+
const total = performance.now() - start;
28+
29+
console.log(
30+
JSON.stringify({
31+
function: "drop_duplicates_fn",
32+
mean_ms: total / ITERATIONS,
33+
iterations: ITERATIONS,
34+
total_ms: total,
35+
}),
36+
);
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* Benchmark: duplicatedSeries / duplicatedDataFrame — standalone duplicated detection on 100k elements.
3+
* Outputs JSON: {"function": "duplicated_fn", "mean_ms": ..., "iterations": ..., "total_ms": ...}
4+
*/
5+
import { Series, DataFrame, duplicatedSeries, duplicatedDataFrame } from "../../src/index.ts";
6+
7+
const SIZE = 100_000;
8+
const WARMUP = 5;
9+
const ITERATIONS = 50;
10+
11+
const s = new Series({ data: Array.from({ length: SIZE }, (_, i) => i % 1000) });
12+
const df = new DataFrame({
13+
a: Array.from({ length: SIZE }, (_, i) => i % 1000),
14+
b: Array.from({ length: SIZE }, (_, i) => i % 500),
15+
});
16+
17+
for (let i = 0; i < WARMUP; i++) {
18+
duplicatedSeries(s);
19+
duplicatedDataFrame(df);
20+
}
21+
22+
const start = performance.now();
23+
for (let i = 0; i < ITERATIONS; i++) {
24+
duplicatedSeries(s);
25+
duplicatedDataFrame(df);
26+
}
27+
const total = performance.now() - start;
28+
29+
console.log(
30+
JSON.stringify({
31+
function: "duplicated_fn",
32+
mean_ms: total / ITERATIONS,
33+
iterations: ITERATIONS,
34+
total_ms: total,
35+
}),
36+
);
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* Benchmark: nsmallestSeries — standalone nsmallest on 100k-element Series.
3+
* Outputs JSON: {"function": "nsmallest_series_fn", "mean_ms": ..., "iterations": ..., "total_ms": ...}
4+
*/
5+
import { Series, nsmallestSeries } from "../../src/index.ts";
6+
7+
const SIZE = 100_000;
8+
const WARMUP = 5;
9+
const ITERATIONS = 50;
10+
11+
const s = new Series({ data: Array.from({ length: SIZE }, (_, i) => Math.sin(i * 0.01) * 1000) });
12+
13+
for (let i = 0; i < WARMUP; i++) {
14+
nsmallestSeries(s, 100);
15+
}
16+
17+
const start = performance.now();
18+
for (let i = 0; i < ITERATIONS; i++) {
19+
nsmallestSeries(s, 100);
20+
}
21+
const total = performance.now() - start;
22+
23+
console.log(
24+
JSON.stringify({
25+
function: "nsmallest_series_fn",
26+
mean_ms: total / ITERATIONS,
27+
iterations: ITERATIONS,
28+
total_ms: total,
29+
}),
30+
);

0 commit comments

Comments
 (0)