Skip to content

Conversation

MilesCranmer
Copy link
Contributor

@MilesCranmer MilesCranmer commented May 9, 2023

Fixes #308

This lets you perform, e.g.,

suite = BenchmarkGroup()

for T in [Float32, Float64], n in [10, 100], m in [5, 20]
    suite["sum"][T][n][m] = @benchmarkable sum(x) setup=(x=randn($T, $n, $m))
end

without needing to manually create each benchmark group. Normally you would have to do something like:

suite = BenchmarkGroup()

for T in [Float32, Float64], n in [10, 100], m in [5, 20]
    !haskey(suite, "sum") && (suite["sum"] = BenchmarkGroup())
    !haskey(suite["sum"], T) && (suite["sum"][T] = BenchmarkGroup())
    !haskey(suite["sum"][T], n) && (suite["sum"][T][n] = BenchmarkGroup())

    suite["sum"][T][n][m] = @benchmarkable sum(x) setup=(x=randn($T, $n, $m))
end

which seems tedious.

This is similar to how EasyConfig.jl works, in that getindex will automatically create each required BenchmarkGroup().

The downside is that accessing the wrong key will create empty groups. Thus, there is the clear_empty! command to clean these up (I added docs too).

@MilesCranmer
Copy link
Contributor Author

@vchuravy @ranocha would one of you be up for reviewing this? Note that this is backwards compatible so won’t cause issues in existing code. It simply makes it significantly easier to set up hierarchical benchmark suites over different param combinations.

Copy link
Contributor

@ranocha ranocha left a comment

Choose a reason for hiding this comment

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

I'm not a developer/maintainer of BenchmarkTools.jl and can't really judge this. All I can say is that you should also add some tests.

@MilesCranmer
Copy link
Contributor Author

Thanks. Will definitely add tests; just wanted to have this PR “fail fast” if this feature is a nonstarter

@ranocha
Copy link
Contributor

ranocha commented May 14, 2023

if this feature is a nonstarter

I'm not a developer/maintainer, so I can't comment on this

@MilesCranmer
Copy link
Contributor Author

@vchuravy would you be able to take a look at this? I can add tests if this looks okay as a feature.

@MilesCranmer
Copy link
Contributor Author

@ararslan would you be up for taking a look at this?

@gdalle
Copy link
Collaborator

gdalle commented Jun 12, 2023

@vchuravy just made me a maintainer (hurray 🤣) and it turns out I ran into this very problem last week, so I'm gonna say the feature is a welcome one. Please add tests and I'll review!

@MilesCranmer
Copy link
Contributor Author

Done!

@gdalle
Copy link
Collaborator

gdalle commented Jun 12, 2023

I need to fix CI cause #305 broke it for unsupported Julia versions, then we'll re-run the tests

@gdalle
Copy link
Collaborator

gdalle commented Jun 12, 2023

OK tests are failing outside of 1.5 and 1.7, that's not on me :)

@MilesCranmer
Copy link
Contributor Author

Oops, fixed!

@gdalle gdalle merged commit ae1f8a7 into JuliaCI:master Jun 13, 2023
@gdalle
Copy link
Collaborator

gdalle commented Jun 13, 2023

@MilesCranmer do you think this is a breaking change or a new feature?

@MilesCranmer
Copy link
Contributor Author

I think it’s a breaking change, so worth bumping the version number

@MilesCranmer MilesCranmer deleted the patch-1 branch June 13, 2023 11:24
@gdalle
Copy link
Collaborator

gdalle commented Jun 13, 2023

OK then I'll wait until we fix a few longstanding bugs

@MilesCranmer
Copy link
Contributor Author

@gdalle I noticed a new version has not been released yet and I was wondering if you might be able to do so? Would be great to use this feature!

@gdalle
Copy link
Collaborator

gdalle commented Aug 6, 2023

I have been hesitant cause it's a central package and breaking changes have been made, but a recent discussion on slack convinced me to move forward. Waiting on one PR then I'll do a bit of cleanup and tag 2.0

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.

Automatically create keys in BenchmarkGroup
3 participants