niklas-heer / speed-comparison

A repo which compares the speed of different programming languages.
https://niklas-heer.github.io/speed-comparison
MIT License
475 stars 76 forks source link

Simplify Julia implementation #57

Open giordano opened 1 year ago

giordano commented 1 year ago

Follow up to #52. CC @mcabbott

Moelf commented 1 year ago

oh yeah that's better, same logic as https://github.com/niklas-heer/speed-comparison/pull/51/files#diff-85e0272e1f01d03ce8049536a346d2628b17d12e4e60a1fa6d79fad740478605R3

giordano commented 1 year ago

Static compilation will probably not like this one, ooops :sweat_smile:

mcabbott commented 1 year ago

For me this is not as quick locally, but maybe just a quirk of my CPU?

Edit: fixed now.

```julia 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 ```
niklas-heer commented 1 year ago

It seems to have broken then compiled Julia version. https://github.com/niklas-heer/speed-comparison/actions/runs/3275378446/jobs/5390146368#step:6:1598

giordano commented 1 year ago

Yes, I know :slightly_smiling_face: Someone else is looking into whether StaticCompiler.jl can handle this. It's all very experimental :sweat_smile:

mcabbott commented 1 year ago

Note also that these behave differently at small n:

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
niklas-heer commented 1 year ago

@giordano ah okay, that is what you meant by that. Got it 👍

niklas-heer commented 1 year ago

@giordano I had to update it due to #66

niklas-heer commented 1 year ago

The compiled version still seems broken.

     +julia-compiled *failed* | ERROR Earthfile line 205:2
     +julia-compiled *failed* |       The command
     +julia-compiled *failed* |           RUN julia -e 'using Pkg; Pkg.add(name="StaticTools", version="0.8"); Pkg.add(name="StaticCompiler", version="0.4"); include("./leibniz_compiled.jl"); compile_executable(mainjl, (), "./")'
     +julia-compiled *failed* |       did not complete successfully. Exit code 1
Share your logs with an Earthly account (experimental)! Register for one at https://ci.earthly.dev.
Error: build target: build main: failed to solve: process "/bin/sh -c EARTHLY_LOCALLY=false JULIA_GPG=3673DF529D9049477F76B37566E3C7DC03D6E495 JULIA_PATH=/usr/local/julia JULIA_VERSION=1.8.2 PATH=/usr/local/julia/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin iterations=3 timeas=second warmups=2 /usr/bin/earth_debugger /bin/sh -c 'julia -e '\"'\"'using Pkg; Pkg.add(name=\"StaticTools\", version=\"0.8\"); Pkg.add(name=\"StaticCompiler\", version=\"0.4\"); include(\"./leibniz_compiled.jl\"); compile_executable(mainjl, (), \"./\")'\"'\"''" did not complete successfully: exit code: 1
Error: Process completed with exit code 1.
giordano commented 1 year ago

Yeah, we're hoping https://github.com/tshort/StaticCompiler.jl/pull/85 will help with that

niklas-heer commented 1 year ago

I guess we are still waiting for https://github.com/tshort/StaticCompiler.jl/pull/89?

giordano commented 1 year ago

Yes, which in the meantime became https://github.com/tshort/StaticCompiler.jl/pull/90 (they're having some git-induced troubles over there)

gbaraldi commented 1 year ago

As it turns out. Git is hard :smile_cat:

niklas-heer commented 1 year ago

Got it 👍 Just let me know when I should test it again through the CI @giordano

As it turns out. Git is hard 😸

Hahaha. Yes, that is very true 😄