summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSam Gross <colesbury@gmail.com>2025-01-03 21:48:47 (GMT)
committerGitHub <noreply@github.com>2025-01-03 21:48:47 (GMT)
commitf1574859d7d6cd259f867194762f04b72ef2c340 (patch)
tree66b24ab078353f49ed79b00f136a42f64cace604
parentb75ed951d4de8ba85349d80c8e7f097b3cd6052f (diff)
downloadcpython-f1574859d7d6cd259f867194762f04b72ef2c340.zip
cpython-f1574859d7d6cd259f867194762f04b72ef2c340.tar.gz
cpython-f1574859d7d6cd259f867194762f04b72ef2c340.tar.bz2
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.
-rw-r--r--Tools/ftscalingbench/ftscalingbench.py14
1 files changed, 11 insertions, 3 deletions
diff --git a/Tools/ftscalingbench/ftscalingbench.py b/Tools/ftscalingbench/ftscalingbench.py
index 767aeae..364c465 100644
--- a/Tools/ftscalingbench/ftscalingbench.py
+++ b/Tools/ftscalingbench/ftscalingbench.py
@@ -54,8 +54,16 @@ def object_cfunction():
@register_benchmark
def cmodule_function():
- for i in range(1000 * WORK_SCALE):
- math.floor(i * i)
+ 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(N):
+ 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":