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

bench: add utilities for profiling and tracing benchmarks #4041

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

EdmundGoodman
Copy link
Collaborator

Add the bench_utils file to provide a simple command-line interface for developers to manually run and profile benchmarks outside of ASV.

Peeled off from tracking PR #4008.

@EdmundGoodman EdmundGoodman added the bench Benchmark related changes label Mar 10, 2025
@EdmundGoodman EdmundGoodman self-assigned this Mar 10, 2025
Copy link

codecov bot commented Mar 10, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.24%. Comparing base (f09ad6c) to head (51cdb9e).
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4041      +/-   ##
==========================================
+ Coverage   90.23%   90.24%   +0.01%     
==========================================
  Files         458      457       -1     
  Lines       58369    58401      +32     
  Branches     5687     5691       +4     
==========================================
+ Hits        52671    52706      +35     
+ Misses       4317     4312       -5     
- Partials     1381     1383       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

setup()

offset_start = time.perf_counter()
benchmark_class_empty()
Copy link
Member

Choose a reason for hiding this comment

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

Can you leave a comment somewhere in the code to say why this is useful?

Copy link
Member

Choose a reason for hiding this comment

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

Could be here, or on the class, or in both places

Comment on lines +66 to +70
return (
mean(times) - mean(offset),
median(times) - mean(offset),
stdev(times) + stdev(offset),
)
Copy link
Member

Choose a reason for hiding this comment

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

definitely worth a comment

def get_benchmark_runs(
args: Namespace,
benchmarks: dict[
str, Callable[[], Any] | tuple[Callable[[], Any], Callable[[], Any]]
Copy link
Member

Choose a reason for hiding this comment

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

Worth a typealias?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added type alias -- this also makes the invocation in benchmark files neater which is nice!

EdmundGoodman and others added 2 commits March 10, 2025 15:26
Co-authored-by: Sasha Lopoukhine <[email protected]>
Co-authored-by: Sasha Lopoukhine <[email protected]>
Copy link
Member

@superlopuh superlopuh left a comment

Choose a reason for hiding this comment

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

Very cool

@superlopuh
Copy link
Member

Small note: our convention is to let the original commenter resolve the comments, makes it easier to track whether it's been addressed in the way that was expected.

from statistics import mean, median, stdev
from typing import Any, NamedTuple, cast

DEFAULT_OUTPUT_DIRECTORY = Path(__file__).parent / "profiles"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Isn't more natural to use the current working directory (i.e., os.get_cwd())? it might be convenient for the CI runs ATM though.

Copy link
Collaborator Author

@EdmundGoodman EdmundGoodman Mar 10, 2025

Choose a reason for hiding this comment

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

I did this because it avoids making multiple profiles directories if you run the script in different places, as they are often large and we want to ensure they are correctly gitignored.

If it is confusing behaviour, am happy to change though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bench Benchmark related changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants