Skip to content

Commit f157485

Browse files
authored
gh-125985: Fix cmodule_function() scaling benchmark (#128460)
Add a separate benchmark that measures the effect of `_PyObject_LookupSpecial()` on scaling. In the process of cleaning up the scaling benchmarks for inclusion, I unintentionally changed the "cmodule_function" benchmark to pass an `int` to `math.floor()` instead of a `float`, which causes it to use the `_PyObject_LookupSpecial()` code path. `_PyObject_LookupSpecial()` has its own scaling issues that we want to measure separately from calling a function on a C module.
1 parent b75ed95 commit f157485

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

Tools/ftscalingbench/ftscalingbench.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,16 @@ def object_cfunction():
5454

5555
@register_benchmark
5656
def cmodule_function():
57-
for i in range(1000 * WORK_SCALE):
58-
math.floor(i * i)
57+
N = 1000 * WORK_SCALE
58+
for i in range(N):
59+
math.cos(i / N)
60+
61+
@register_benchmark
62+
def object_lookup_special():
63+
# round() uses `_PyObject_LookupSpecial()` internally.
64+
N = 1000 * WORK_SCALE
65+
for i in range(N):
66+
round(i / N)
5967

6068
@register_benchmark
6169
def mult_constant():
@@ -206,7 +214,7 @@ def benchmark(func):
206214
color = "\x1b[33m" # yellow
207215
reset_color = "\x1b[0m"
208216

209-
print(f"{color}{func.__name__:<18} {round(factor, 1):>4}x {direction}{reset_color}")
217+
print(f"{color}{func.__name__:<25} {round(factor, 1):>4}x {direction}{reset_color}")
210218

211219
def determine_num_threads_and_affinity():
212220
if sys.platform != "linux":

0 commit comments

Comments
 (0)