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

gh-85283: _statistics uses the limited C API#108500

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
vstinner wants to merge1 commit intopython:mainfromvstinner:limit_statistics

Conversation

vstinner
Copy link
Member

@vstinnervstinner commentedAug 25, 2023
edited by bedevere-bot
Loading

Argument Clinic supports positional-only arguments for the limited C API.

Argument Clinic supports positional-only arguments for the limited CAPI.
@vstinner
Copy link
MemberAuthor

With this change,_statistics._normal_dist_inv_cdf() usesless efficient code to parse its arguments:

  • UseMETH_VARARGS calling convention (pass arguments as a tuple), instead ofMETH_FASTCALL (no Python object needed to pass arguments)
  • UsePyArg_ParseTuple() to parse arguments with the"ddd:_normal_dist_inv_cdf" string.PyArg_ParseTuple() has to parse the format string. Instead of using inlined code_PyArg_CheckPositional(),PyFloat_CheckExact() /PyFloat_AsDouble() andPyFloat_AS_DOUBLE().

@vstinner
Copy link
MemberAuthor

Micro-benchmark on Linux with CPU isolation, Python built with-O3 (without LTO, without PGO):

$ python -m pyperf compare_to ref.json limited.json Mean +- std dev: [ref] 88.6 ns +- 1.5 ns -> [limited] 160 ns +- 1 ns: 1.81x slower

Code:

import _statisticsimport pyperfp = 0.5mu = 0.0sigma = 1.0runner = pyperf.Runner()runner.bench_func('inv_cdf', _statistics._normal_dist_inv_cdf, p, mu, sigma)

@vstinner
Copy link
MemberAuthor

I'm not sure if the_statistics is a good candidate for this work on converting stdlib extensions to the limited C API. TheLib/statistics.py module has a pure Python implementation, and the C code is there for optimization. So I would expect best performance for that. Moreover, the function is quite fast, around 100 ns, so the cost of argument parsing is significant.

nickodell reacted with thumbs up emoji

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@vstinner@bedevere-bot

[8]ページ先頭

©2009-2025 Movatter.jp