Skip to content

Add warnings about too few or too many samples#210

Merged
mdboom merged 7 commits intopsf:mainfrom
mdboom:estimate-sample-size
Dec 19, 2024
Merged

Add warnings about too few or too many samples#210
mdboom merged 7 commits intopsf:mainfrom
mdboom:estimate-sample-size

Conversation

@mdboom
Copy link
Copy Markdown
Collaborator

@mdboom mdboom commented Dec 17, 2024

Related to python/pyperformance#372. Once this is merged, we can reduce the number of iterations in pyperformance.

@mdboom mdboom requested a review from vstinner December 17, 2024 19:08
pyperf/_bench.py Outdated

https://en.wikipedia.org/wiki/Sample_size_determination#Estimation_of_a_mean
"""
# Get the means of the values per run
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why not computing the mean only once, for all values of all runs?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Because for some benchmarks, cache effects are visible within the same process. For example, pylint takes about 30% longer during the first iteration than the subsequent 2 iterations. One could argue that's a bad benchmark, but it's common enough that we should control for it. There's some more discussion here: faster-cpython/bench_runner#318 (comment)

That said, it's definitely worth putting a comment about that here.

pyperf/_cli.py Outdated
lines.append(
"Consider passing processes=%d to the Runner constructor to save time." %
required_nsamples
)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This warning may be a little bit annoying. Maybe only show it in the "pyperf check" command? https://pyperf.readthedocs.io/en/latest/cli.html#check-cmd

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, that's a good idea. We can run check in our own infra, which is good enough for me.

pyperf/_bench.py Outdated
raise ValueError("MAD must be >= 0")
return value

def required_nsamples(self):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If you want to add a public function, please document it at: https://pyperf.readthedocs.io/en/latest/api.html#benchmark-class

Copy link
Copy Markdown
Collaborator Author

@mdboom mdboom Dec 18, 2024

Choose a reason for hiding this comment

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

Good point. I think we do want it to be public (for the same reason the other statistics methods are public).

@mdboom mdboom requested a review from vstinner December 18, 2024 19:08

def test_check_stable(self):
stdout = self.run_command('check', TELCO)
self.assertTrue(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I suggest using assertIn() instead.

Co-authored-by: Victor Stinner <vstinner@python.org>
Copy link
Copy Markdown
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

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

The code change LGTM. I didn't check the maths behind required_nprocesses().

@mdboom mdboom merged commit bbc8e9f into psf:main Dec 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants