GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-85283: _statistics uses the limited C API by vstinner · Pull Request #108500 · python/cpython

Conversation

@vstinner

@vstinner vstinner commented Aug 25, 2023 •
edited by bedevere-bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

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

  • Issue: [C API] Convert a few stdlib extensions to the limited C API (PEP 384) #85283

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@vstinner
pythongh-85283: _statistics uses the limited C API
d79b059
Argument Clinic supports positional-only arguments for the limited C
API.
@bedevere-bot bedevere-bot mentioned this pull request Aug 25, 2023
[C API] Convert a few stdlib extensions to the limited C API (PEP 384) #85283
Closed
@bedevere-bot bedevere-bot added the awaiting core review label Aug 25, 2023
@vstinner

vstinner commented Aug 25, 2023

Copy link
Copy Markdown
Member Author

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

  • Use METH_VARARGS calling convention (pass arguments as a tuple), instead of METH_FASTCALL (no Python object needed to pass arguments)
  • Use PyArg_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() and PyFloat_AS_DOUBLE().
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner

vstinner commented Aug 25, 2023

Copy link
Copy Markdown
Member Author

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 _statistics
import pyperf

p = 0.5
mu = 0.0
sigma = 1.0

runner = pyperf.Runner()
runner.bench_func('inv_cdf', _statistics._normal_dist_inv_cdf, p, mu, sigma)
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner

vstinner commented Aug 25, 2023

Copy link
Copy Markdown
Member Author

I'm not sure if the _statistics is a good candidate for this work on converting stdlib extensions to the limited C API. The Lib/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
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner
vstinner marked this pull request as draft August 25, 2023 23:13
@bedevere-bot bedevere-bot removed the awaiting core review label Aug 25, 2023
@vstinner vstinner closed this Aug 26, 2023
@vstinner
vstinner deleted the limit_statistics branch August 26, 2023 03:03
@vstinner vstinner mentioned this pull request Mar 17, 2024
gh-85283: Build _statistics extension with the limited C API #116927
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@vstinner @bedevere-bot
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.