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

Option to disable the default output entirely [#193] #224

Merged
merged 5 commits into from
Oct 15, 2019
Merged

Option to disable the default output entirely [#193] #224

merged 5 commits into from
Oct 15, 2019

Conversation

knidarkness
Copy link
Contributor

This PR addresses the #193 Feature request. It allows to pass none as a value for --style option.

If it is used, then no output (unless they are errors).

@sharkdp , may be there is some sense to print warnings as well. What do you think?

Copy link
Owner

@sharkdp sharkdp left a comment

Choose a reason for hiding this comment

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

Thank you very much for working on this!

src/hyperfine/benchmark.rs Outdated Show resolved Hide resolved
src/hyperfine/benchmark.rs Outdated Show resolved Hide resolved
@@ -221,17 +231,21 @@ pub fn run_benchmark(
options.failure_action,
None,
)?;
progress_bar.inc(1);
if let Some(pbar) = progress_bar.clone() { pbar.inc(1); }
Copy link
Owner

Choose a reason for hiding this comment

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

We should avoid .clone()ing. You can probably use if let Some(ref pbar) = …

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, thanks, you were right, that works well and improves performance, although that (performance) doesn't seem crucial for this case?

Copy link
Owner

Choose a reason for hiding this comment

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

no, it's not. but I think its much cleaner without cloning it everywhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, totally agree on that

Copy link
Owner

Choose a reason for hiding this comment

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

Coming to think of it, there is an even cleaner solution to write this, that we should probably follow. You can use map to "directly" call a function on the object inside the Option, allowing us to get rid of all the if statements. Should be something like

progress_bar.map(|bar| bar.inc(1));

or

progress_bar.as_ref().map(|bar| bar.inc(1));

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, that looks quite interesting, but do you think it's that readable?

Copy link
Owner

@sharkdp sharkdp Oct 14, 2019

Choose a reason for hiding this comment

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

Yes, I think that's readable. Using .map(…) on Option, Result, or any kind of Iterator is very common in Rust code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, seems quite nice when I researched a bit more. Updated the PR with that way

src/hyperfine/benchmark.rs Outdated Show resolved Hide resolved
src/hyperfine/benchmark.rs Outdated Show resolved Hide resolved
src/hyperfine/benchmark.rs Outdated Show resolved Hide resolved
src/hyperfine/benchmark.rs Outdated Show resolved Hide resolved
src/hyperfine/benchmark.rs Outdated Show resolved Hide resolved
src/hyperfine/types.rs Outdated Show resolved Hide resolved
src/main.rs Outdated
@@ -54,8 +54,9 @@ fn main() {

match res {
Ok(timing_results) => {
write_benchmark_comparison(&timing_results);
let ans = export_manager.write_results(timing_results, options.unwrap().time_unit);
let unwrapped = options.unwrap();
Copy link
Owner

Choose a reason for hiding this comment

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

instead of calling it unwrapped, we could call it options and shadow the original name.

The fact that we call unwrap here anyway is not really great, but that should be fixed elsewhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated with shodowing for now. do you have any ideas on re-writing in the way not to have to unwrap the options object?

@knidarkness
Copy link
Contributor Author

Thanks for the review! Sorry for taking your time for those quite simple things, not too much in Rust yet and decided to improve myself in it during Hacktoberfest.

Will update up to your comments today/tomorrow.

@knidarkness
Copy link
Contributor Author

@sharkdp , I have updated the PR as you have described. Again, thanks a lot for lots of useful comments.

Copy link
Owner

@sharkdp sharkdp left a comment

Choose a reason for hiding this comment

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

Thank you very much for the updates!

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