-
-
Notifications
You must be signed in to change notification settings - Fork 358
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
Conversation
This commit allows to remove all non-errornous output of the tool.
There was a problem hiding this 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
@@ -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); } |
There was a problem hiding this comment.
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) = …
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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));
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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/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(); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
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. |
@sharkdp , I have updated the PR as you have described. Again, thanks a lot for lots of useful comments. |
There was a problem hiding this 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!
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?