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 possibility to pass float values or range to --parameter-scan #184

Closed
guilhermeleobas opened this issue Jun 29, 2019 · 11 comments
Closed
Labels

Comments

@guilhermeleobas
Copy link

When using hyperfine, I am missing the possibility of specifying a range or floating point values on --parameter-scan:

hyperfine --parameter-scan i 1 10 2 "sleep {i}"

or

hyperfine --parameter-scan i 0.1 1.0 "sleep {i}"
@sharkdp
Copy link
Owner

sharkdp commented Jul 9, 2019

Thank you for the feedback. What CLI would you propose for this? We can't let --parameter-scan take an optional fourth argument.

@guilhermeleobas
Copy link
Author

guilhermeleobas commented Jul 10, 2019

I was thinking in use --parameter-scan with an optional fourth argument but since that is not possible, maybe use --parameter-range-scan with the same semantics of the former but with a parameter indicating the range increment.

edit: Can --parameter-scan take a float parameter?

edit2: Or instead of adding a floating point option, add a way to format the variable generate by --parameter-scan using the printf notation. For instance:

> hyperfine --parameter-scan var 1 5 --format "0.%.f"  "echo {var}"
0.1
0.2
0.3
0.4
0.5

@sharkdp
Copy link
Owner

sharkdp commented Jul 10, 2019

Another possibility would be to keep --parameter-scan as it is, and add a new --parameter-step-size <step> (or --step-size <step>) option.

@sharkdp
Copy link
Owner

sharkdp commented Jul 10, 2019

edit2: Or instead of adding a floating point option, add a way to format the variable generate by --parameter-scan using the printf notation.

You can already do this - sort of.

With bc:

hyperfine -P var 1 5 'sleep $(echo "{var}/10" | bc -l)'

With zsh:

hyperfine -S zsh -P var 1 5 'sleep $(({var}.0/10))'

@piyushrungta25
Copy link
Contributor

@sharkdp Opened #203 to add --parameter-step-size argument.

@sharkdp
Copy link
Owner

sharkdp commented Aug 24, 2019

@piyushrungta25 has added support for --parameter-step-size in #203. I think it would be great if we could also add support for floating point values, such that we can run things like:

hyperfine --parameter-scan var 0.0 1.6 --parameter-step-size 0.1 …

@piyushrungta25
Copy link
Contributor

piyushrungta25 commented Aug 26, 2019

I think it would be great if we could also add support for floating point values

I see two issues with this.

  1. Choosing default value of the step. Something like 0.1 as the default doesn't seem very intuitive. One thing we can do is make the step size argument required for ranges with float bounds.

  2. The range iterators in std library(or even num crate) does not take float parameters. So if we are okay with rolling our own iterator, I can come up with an implementation.

@sharkdp
Copy link
Owner

sharkdp commented Aug 26, 2019

  1. Choosing default value of the step. Something like 0.1 as the default doesn't seem very intuitive. One thing we can do is make the step size argument required for ranges with float bounds.

Good point. I would definitely not choose 0.1 as the default, yes. Requiring the step size to be set for float arguments sounds like a good idea to me!

  1. The range iterators in std library(or even num crate) does not take float parameters. So if we are okay with rolling our own iterator,

I'd be okay with this, as long as it comes with proper unit tests. I could imagine that the reason for the absence in the standard library is the following unfortunate property of floating point numbers:

Imagine that someone chooses --parameter-scan var 0.0 1.0 and a step size of 0.1. I think that most users would expect the 1.0 boundary to be inclusive. However, due to rounding errors, a naive implementation could miss the 1.0 boundary due to 0.0 + 10 * 0.1 being too large.

I guess this could probably be circumvented by computing N = (end - start) / stepsize and testing if it is close to an integer number. In this special case, we could round N to that nearby integer and make sure that we perform exactly N incrementations (or N+1 benchmarks).

I can come up with an implementation.

👍

@piyushrungta25
Copy link
Contributor

unfortunate property of floating point numbers

Perhaps a decimal data type would be more appropriate here? This would prevent substitutions like echo 0.30000000000000004 from happening.

@sharkdp
Copy link
Owner

sharkdp commented Sep 1, 2019

This has been fully implemented by @piyushrungta25 🎆

@sharkdp sharkdp closed this as completed Sep 1, 2019
@sharkdp
Copy link
Owner

sharkdp commented Sep 1, 2019

Released in hyperfine v1.7.0

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

No branches or pull requests

3 participants