Usage of lazy vector instead of function

This is a shame about M1ā€¦

Removing the +2 gave me a 5% more :

g7(n) = 16*(sum(x -> (b = 4float(x)^2; a = b+3; a/(a^2-16b)), 2:4:(n+1)))

So, @giordano, the conclusion is that

function f(rounds)
    p = 1.0
    @simd for i in 2:(rounds + 2)
        x = (-1)^iseven(i)
        p += x / (2 * i - 1)
    end
    p *= 4
    return p
end

g7(n) = 16*(sum(x -> (b = 4float(x)^2; a = b+3; a/(a^2-16b)), 2:4:(n+1)))

@btime f(10^8)
@btime g7(10^8)

gives

  43.530 ms (0 allocations: 0 bytes)
  11.347 ms (0 allocations: 0 bytes)

So you might update your graph :rofl: Also, iā€™m guessing that the other Julia in your graph might go up a little bit.

3 Likes

Is llvm smart enough to turn x = (-1)^iseven(i) into x = 2*isodd(i)-1?

1 Like
3 Likes