Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lib/random.py: use more efficient code to convert bytes to integer #65593

Closed
vstinner opened this issue Apr 30, 2014 · 3 comments
Closed

Lib/random.py: use more efficient code to convert bytes to integer #65593

vstinner opened this issue Apr 30, 2014 · 3 comments
Labels
easy performance Performance or resource usage

Comments

@vstinner
Copy link
Member

BPO 21394
Nosy @vstinner, @PCManticore

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2014-04-30.22:33:31.734>
created_at = <Date 2014-04-30.10:07:47.595>
labels = ['easy', 'performance']
title = 'Lib/random.py: use more efficient code to convert bytes to integer'
updated_at = <Date 2014-04-30.22:33:31.733>
user = 'https://github.com/vstinner'

bugs.python.org fields:

activity = <Date 2014-04-30.22:33:31.733>
actor = 'vstinner'
assignee = 'none'
closed = True
closed_date = <Date 2014-04-30.22:33:31.734>
closer = 'vstinner'
components = []
creation = <Date 2014-04-30.10:07:47.595>
creator = 'vstinner'
dependencies = []
files = []
hgrepos = []
issue_num = 21394
keywords = ['easy']
message_count = 3.0
messages = ['217595', '217599', '217663']
nosy_count = 2.0
nosy_names = ['vstinner', 'Claudiu.Popa']
pr_nums = []
priority = 'normal'
resolution = 'fixed'
stage = None
status = 'closed'
superseder = None
type = 'performance'
url = 'https://bugs.python.org/issue21394'
versions = ['Python 3.5']

@vstinner
Copy link
Member Author

In Lib/random.py, I see lines like that:

long(_hexlify(_urandom(32)), 16)

I guess that something more efficient can be fonud to convert a bytes string to an integer.

bytes.from_bytes() maybe?

@vstinner vstinner added easy performance Performance or resource usage labels Apr 30, 2014
@PCManticore
Copy link
Mannequin

PCManticore mannequin commented Apr 30, 2014

Do you mean int.from_bytes?

It's already changed in Python 3.5: int.from_bytes(_urandom(32), 'big').

@vstinner
Copy link
Member Author

Oops, I didn't read the right version of the code.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
easy performance Performance or resource usage
Projects
None yet
Development

No branches or pull requests

1 participant