-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Benchmark {Float,Double,Float80}.description #15234
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
Benchmark {Float,Double,Float80}.description #15234
Conversation
This just tests how fast we can format the standard floating-point types. It also includes a test that uses the result, to ensure that future optimized _creation_ of the string doesn't incidentally pessimize _use_ of the results.
This just tests how fast we can format the standard floating-point types. It also includes a test that uses the result, to ensure that future optimized _creation_ of the string doesn't incidentally pessimize _use_ of the results.
In particular, I'd appreciate a check whether the |
@swift-ci Please smoke benchmark |
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.
LGTM, just some small fixes
for i in 0..<count { | ||
let raw = UInt32(i) * step | ||
let f = Float(bitPattern: raw) | ||
s = f.description |
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.
You can write this as: blackHole(f.description)
Blackhole is from TestUtils.swift, which has a few no-op functions that the optimizer cannot see into (separate module). This way you can avoid trying to trick the optimizer and have trivial uses of values.
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.
Thanks for pointing that out. That's much cleaner.
for i in 0..<count { | ||
let raw = UInt32(i) * step | ||
let f = Float(bitPattern: raw) | ||
s = "result was \(f)" |
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.
Is your intention to avoid having the final string be small? If so, blackHole("and the actual result was \(f)")
is more future proof, as not even a 5-bit encoding can store this.
for _ in 0..<N { | ||
for i in 0..<count { | ||
let fraction = UInt64(i) * step | ||
let exponent = UInt(i) % 32768 |
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.
CC @stephentyrone as I don't know how to benchmark floats (or the magic numbers).
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.
This is fine.
Build comment file:Optimized (O)Regression (15)
Improvement (26)
No Changes (346)
Added (6)
Unoptimized (Onone)Regression (9)
Improvement (14)
No Changes (364)
Added (6)
Hardware Overview
|
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.
Can you add a second set that benches only "nicely-scaled" values? Uniform on [0,1000] or similar. We wouldn't want to regress those cases for a modest win on all FloatingPoint values.
@stephentyrone - Did you want to test values with short text forms or values close to 1? Generally speaking, manually-typed values in code tend to be both. The easiest way to generate such numbers would be something like:
|
Values with modest exponents is what I really have in mind; it's common for input values to have short-forms, but not especially common for results that get printed, so I'm less concerned about that. I'd be OK with even your very simple example for now, as long as we have some coverage for this case. |
…swift into tbkka-float-description-benchmark
@swift-ci Please smoke benchmark |
@stephentyrone - I now have
|
…swift into tbkka-float-description-benchmark
Build comment file:Build failed before running benchmark. |
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.
Thanks @tbkka !
@swift-ci Please smoke benchmark |
@swift-ci please smoke test |
Build comment file:Build failed before running benchmark. |
This just tests how fast we can produce
.description
for the standard floating-point types. It also includes a benchmark that actually does something with the result, to check whether future optimizations to the creation of the string accidentally pessimize use of the results.