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

Add ArgName() and ArgNames() methods to name arguments/ranges. #305

Merged
merged 4 commits into from
Oct 26, 2016

Conversation

mkurdej
Copy link
Contributor

@mkurdej mkurdej commented Oct 24, 2016

This PR allows the user to name arguments/ranges.

Instead of showing only "benchmark/1" (when called with Arg(1)), one can call the benchmark with Arg(1)->ArgName("arg") and the displayed name will be "benchmark/arg:1".
Readability purposes only.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 17e1c40 on mkurdej:arg-names into * on google:master*.

@AppVeyorBot
Copy link

Build benchmark 486 completed (commit 04692ab0a4 by @mkurdej)

while (state.KeepRunning()) {
}
}
BENCHMARK(BM_arg_name)->Arg(3)->ArgName("first");
Copy link
Member

Choose a reason for hiding this comment

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

what happens if i call Args({1, 3})->ArgName("first") or if I call ArgName directly on the benchmark without Args being set?

Would this be a cleaner api if Args took a map<string, int>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, to preserve current behaviour, the output will be exactly as in the current version if you do not specify ArgName. If you have more arguments than names, than only the first will be named.
One can find it a possible source of incoherence, but that's similar to the behaviour of Args, imagine calling it as Args({1, 2, 3})->Args({1, 2})->Args({1,2,3,4,5}) - that's user's responsibility to define all the arguments its benchmark will need.

For your suggestion, I find it a bit "heavy" to set argument names each time, I would certainly not want to have to write this: Args{{"first", 1}, {"second", 3}}->Args{{"first", 2}, {"second", 5}} and so on. And it is disturbing that the same argument can be named differently each time (or isn't it?)

Anyway, your remarks made me think of a case that I didn't anticipate: the user might want to name only few arguments, e.g. ArgNames({"first", "", "third"}), my current PR will write BM_benchmark/first:1/:2/third:3 (note the semicolon before 2). I'll correct it ASAP.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling c1c01b2 on mkurdej:arg-names into * on google:master*.

@AppVeyorBot
Copy link

Build benchmark 487 completed (commit 5cef4c6beb by @mkurdej)

}

Benchmark* Benchmark::ArgNames(const std::vector<std::string>& names) {
arg_names_ = names;
Copy link
Member

Choose a reason for hiding this comment

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

should this be called after Args? If we can add a constraint on that, and then check that names.size() == args.size(), i think it would be much clearer to users when they do something unexpected. what do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, I see now that there are checks in Arg/Args/Range/Ranges/DenseRange that use ArgsCnt. Previously I thought that you could call Args with different number of elements each time.
I'll add these checks then, it seems to be the way to go.

Copy link
Contributor Author

@mkurdej mkurdej Oct 26, 2016

Choose a reason for hiding this comment

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

I've added the constraint for the size. I've also modified ArgsCnt, so that it could be possible to call Args and ArgNames in any order. If you see a simpler/more elegant way to do this, I'm all ears.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling cfee1a5 on mkurdej:arg-names into * on google:master*.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 3f23832 on mkurdej:arg-names into * on google:master*.

@AppVeyorBot
Copy link

Build benchmark 488 completed (commit c0d40d1987 by @mkurdej)

@AppVeyorBot
Copy link

Build benchmark 489 completed (commit cc8d4c6804 by @mkurdej)

@dmah42 dmah42 merged commit 3f23832 into google:master Oct 26, 2016
@dmah42
Copy link
Member

dmah42 commented Oct 26, 2016

Thanks!

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

Successfully merging this pull request may close these issues.

5 participants