-
Notifications
You must be signed in to change notification settings - Fork 81
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
Simplify Julia implementation #57
base: master
Are you sure you want to change the base?
Conversation
oh yeah that's better, same logic as https://github.com/niklas-heer/speed-comparison/pull/51/files#diff-85e0272e1f01d03ce8049536a346d2628b17d12e4e60a1fa6d79fad740478605R3 |
Static compilation will probably not like this one, ooops 😅 |
For me this is not as quick locally, but maybe just a quirk of my CPU? Edit: fixed now. julia> f_57(n) = sum(i -> 4/i, (-2 * n + 1):4:(2 * n)) # this PR, one-line
fm (generic function with 1 method)
julia> @btime f_52(10^6) - pi
min 398.584 μs, mean 403.151 μs (0 allocations)
-9.999999823762096e-7
julia> @btime f_57(10^6) - pi # loop with @simd, any variant
min 736.042 μs, mean 739.643 μs (0 allocations)
-9.999999903698154e-7
julia> @btime f_orig(10^6) - pi # with x = -x inside loop
min 1.552 ms, mean 1.569 ms (0 allocations)
-9.999980186137236e-7
julia> versioninfo()
Julia Version 1.9.0-DEV.1528
Platform Info:
OS: macOS (arm64-apple-darwin21.1.0)
CPU: 8 × Apple M1 |
It seems to have broken then compiled Julia version. |
Yes, I know 🙂 Someone else is looking into whether StaticCompiler.jl can handle this. It's all very experimental 😅 |
Note also that these behave differently at small julia> g(i) = 4 / i;
julia> f_1st(rounds) = sum(g, (-2 * rounds + 1):4:(2 * rounds));
julia> f_2nd(n) = sum(i -> 4/(4i-2n-3), 1:n);
julia> hcat(f_orig.(1:10), f_1st.(1:10), f_2nd.(1:10))
10×3 Matrix{Float64}:
3.46667 -4.0 -4.0
2.89524 2.66667 2.66667
3.33968 -3.46667 -3.46667
2.97605 2.89524 2.89524
3.28374 -3.33968 -3.33968
3.01707 2.97605 2.97605
3.25237 -3.28374 -3.28374
3.04184 3.01707 3.01707
3.23232 -3.25237 -3.25237
3.0584 3.04184 3.04184 |
@giordano ah okay, that is what you meant by that. Got it 👍 |
The compiled version still seems broken.
|
Yeah, we're hoping tshort/StaticCompiler.jl#85 will help with that |
1e2d6bb
to
818b522
Compare
I guess we are still waiting for tshort/StaticCompiler.jl#89? |
Yes, which in the meantime became tshort/StaticCompiler.jl#90 (they're having some git-induced troubles over there) |
As it turns out. Git is hard 😸 |
Got it 👍 Just let me know when I should test it again through the CI @giordano
Hahaha. Yes, that is very true 😄 |
Co-authored-by: Michael Abbott <[email protected]>
Follow up to #52. CC @mcabbott