-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Improve performance of ParseUfloat #1865
Conversation
Replaced `offset` handling logic with more efficient math.Pow10 based calculation. goos: linux goarch: amd64 pkg: github.com/valyala/fasthttp cpu: Intel(R) Core(TM) i7-4790 CPU @ 3.60GHz │ old.txt │ new.txt │ │ sec/op │ sec/op vs base │ ParseUfloat-8 44.22n ± 0% 31.06n ± 0% -29.76% (n=50)
This is the first time I'm noticing that our
|
Actually, I encountered this problem as well. I believe the reason is that we use a |
This is currently not documented at all. I'm thinking I would rather have the function return the correct values even for big numbers than have it be 20ns faster. Just using |
Parse the float string is a complex topic. In
|
There are other inconsistencies as well. For example this test fails because it returns
Or parsing |
In the first case |
The second case is very strange. Our algorithm calculates using fmt.Printf("%f %f\n", float64(870000000002)*math.Pow10(-1), float64(870000000002)/math.Pow10(1))
|
|
The example you provided, using |
Lets just call |
Thanks! |
Replaced
offset
handling logic with more efficientmath.Pow10
based calculation.The
math.Pow10
function performs calculations using a lookup table, which is more efficient compared to the original method of continuous division. By switching to simple addition and subtraction operations, the execution time is reduced by approximately 30%.