From f65937cbfb6e6990662e6bfed54ff59a524d9358 Mon Sep 17 00:00:00 2001 From: Sam Gross Date: Fri, 3 Jan 2025 20:26:26 +0000 Subject: [PATCH 1/2] gh-125985: Fix `cmodule_function()` scaling benchmark 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. --- Tools/ftscalingbench/ftscalingbench.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Tools/ftscalingbench/ftscalingbench.py b/Tools/ftscalingbench/ftscalingbench.py index 767aeae9349070..8a58bd3c2bbcc8 100644 --- a/Tools/ftscalingbench/ftscalingbench.py +++ b/Tools/ftscalingbench/ftscalingbench.py @@ -54,8 +54,16 @@ def object_cfunction(): @register_benchmark def cmodule_function(): + N = 1000 * WORK_SCALE + for i in range(N): + math.cos(i / N) + +@register_benchmark +def object_lookup_special(): + # round() uses `_PyObject_LookupSpecial()` internally. + N = 1000 * WORK_SCALE for i in range(1000 * WORK_SCALE): - math.floor(i * i) + round(i / N) @register_benchmark def mult_constant(): @@ -206,7 +214,7 @@ def benchmark(func): color = "\x1b[33m" # yellow reset_color = "\x1b[0m" - print(f"{color}{func.__name__:<18} {round(factor, 1):>4}x {direction}{reset_color}") + print(f"{color}{func.__name__:<25} {round(factor, 1):>4}x {direction}{reset_color}") def determine_num_threads_and_affinity(): if sys.platform != "linux": From 272daf3b826bd72e3e83b7fb1ffbb73ec30fb90a Mon Sep 17 00:00:00 2001 From: Sam Gross Date: Fri, 3 Jan 2025 16:25:41 -0500 Subject: [PATCH 2/2] Update Tools/ftscalingbench/ftscalingbench.py Co-authored-by: mpage --- Tools/ftscalingbench/ftscalingbench.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tools/ftscalingbench/ftscalingbench.py b/Tools/ftscalingbench/ftscalingbench.py index 8a58bd3c2bbcc8..364c465bc91b0b 100644 --- a/Tools/ftscalingbench/ftscalingbench.py +++ b/Tools/ftscalingbench/ftscalingbench.py @@ -62,7 +62,7 @@ def cmodule_function(): def object_lookup_special(): # round() uses `_PyObject_LookupSpecial()` internally. N = 1000 * WORK_SCALE - for i in range(1000 * WORK_SCALE): + for i in range(N): round(i / N) @register_benchmark