Skip to content

Conversation

@rhettinger
Copy link
Contributor

@rhettingerrhettinger commented Oct 31, 2020

Moves the int(x) == x test and conversion into the C code for operator.index().

Provides a 7% speed up:

$ pytime -s 'from random import randrange' 'randrange(15)' # baseline 500000 loops, best of 11: 540 nsec per loop $ pytime -s 'from random import randrange' 'randrange(15)' # new versio 500000 loops, best of 11: 502 nsec per loop 

It should become even faster when we get a zero-cost try.

It's odd that non-integers raise a ValueError. I think that should have been TypeError.

https://bugs.python.org/issue42222

Copy link
Member

@serhiy-storchakaserhiy-storchaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently you are on the way to #19112 (which already has tests and documentation and cover corner cases).

@github-actions
Copy link

This PR is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 5 days

@github-actionsgithub-actionsbot added the stale Stale PR or inactive for long period of time. label Dec 16, 2020
@rhettingerrhettinger removed the stale Stale PR or inactive for long period of time. label Dec 24, 2020
@serhiy-storchaka
Copy link
Member

What about #19112?

@rhettinger
Copy link
ContributorAuthor

I merged in the relevant parts of #19112. The principal differences are:

  • The TypeError won't start being emitted until the after the deprecation period.
  • Improved wording for the doc entries.
  • Tests focus solely on the deprecations.
  • All existing behavior remains intact until after the deprecation.

@serhiy-storchaka
Copy link
Member

  • The TypeError won't start being emitted until the after the deprecation period.

As in #19112 initially. I changed ValueError to TypeError on your request.

  • Improved wording for the doc entries.

I would appreciate any suggestions to change wording.

  • Tests focus solely on the deprecations.

Yes, tests in #19112 cover more cases.

  • All existing behavior remains intact until after the deprecation.

As well as in #19112.

But this PR still has issues. It does not emit warning for randrange(10, 20, 1.0).

@rhettingerrhettinger merged commit a9621bb into python:masterDec 28, 2020
@bedevere-bot
Copy link

@rhettinger: Please replace # with GH- in the commit message next time. Thanks!

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performancePerformance or resource usage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@rhettinger@serhiy-storchaka@bedevere-bot@the-knights-who-say-ni