Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Slow functions calls for C-coded functions, accepting positional-or-kwarg argument vs positional-only #136681

Open
Assignees
skirpichev
Labels
@skirpichev

Description

@skirpichev

Bug report

Bug description:

I don't see measurable difference on pure-Python level, e.g. for

# a.pyimportpyperfdeff1(x):return1deff2(x,/):return1runner=pyperf.Runner()runner.bench_func("f1(1)",f1,1)runner.bench_func("f2(1)",f2,1)

I got on 3.13:

$ python a.py -qf1(1): Mean +- std dev: 233 ns +- 2 nsf2(1): Mean +- std dev: 232 ns +- 2 ns

But for functions, implemented in C, using the Argument Clinic - the difference is bigger:

$ python bench.py -q -o patch.jsonisfinite(1.0): Mean +- std dev: 152 ns +- 1 ns$ git checkout master && make -sChecked 114 modules (35 built-in, 78 shared, 1 n/a on linux-x86_64, 0 disabled, 0 missing, 0 failed on import)$ python bench.py -q -o ref.jsonisfinite(1.0): Mean +- std dev: 136 ns +- 1 ns
Benchmarkrefpatch
isfinite(1.0)136 ns152 ns: 1.12x slower

(In the second version - the math.isfinite() accept also keyword argumentx)

a patch

(run ./python Tools/clinic/clinic.py Modules/mathmodule.c !)

diff --git a/Modules/mathmodule.c b/Modules/mathmodule.cindex 7c2a421dd6..e33281ac8b 100644--- a/Modules/mathmodule.c+++ b/Modules/mathmodule.c@@ -3156,14 +3156,13 @@ math_radians_impl(PyObject *module, double x) math.isfinite      x: double-    /  Return True if x is neither an infinity nor a NaN, and False otherwise. [clinic start generated code]*/  static PyObject * math_isfinite_impl(PyObject *module, double x)-/*[clinic end generated code: output=8ba1f396440c9901 input=46967d254812e54a]*/+/*[clinic end generated code: output=8ba1f396440c9901 input=a47ad6e72998b81d]*/ {     return PyBool_FromLong((long)isfinite(x)); }

This performance penalty affects API decisions (e.g.#131886) and that looks as a bug.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions


    [8]ページ先頭

    ©2009-2025 Movatter.jp