Skip to content

Conversation

@dhana2403
Copy link

@dhana2403 dhana2403 commented Apr 23, 2025

[Update var_access_benchmark.py] Improve performance of timing[GH-132844]

Summary
This PR simplifies the timing logic in the main block by using the number parameter of timeit.Timer, which eliminates the need to manually multiply by iteration counts.

Changes Made
Replaced:
timing = min(Timer(f).repeat(7, 1000))
timing *= 1000000 / (len(trials) * steps_per_trial)

with:
timing = min(Timer(f, number=1000).repeat(7, 1))
timing = (timing * 1e6) / 1000 # ns per single call

Rationale

Makes the code more readable and self-contained
Removes the need for external variables like steps_per_trial and len(trials)
No change in functionality or output

@python-cla-bot
Copy link

python-cla-bot bot commented Apr 23, 2025

All commit authors signed the Contributor License Agreement.

CLA signed

@bedevere-app
Copy link

bedevere-app bot commented Apr 23, 2025

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@Fidget-Spinner
Copy link
Member

Sorry but we don't want to change var_access_benchmark as it invalidates old data that anyone else might have. Thus I'm closing this PR. So sorry!

There's plenty of open issues and other ways to help out too. I recommend reading the devguide if you haven't already https://devguide.python.org/ .

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants