-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Open
Labels
foldsum, maximum, reduce, foldl, etc.sum, maximum, reduce, foldl, etc.performanceMust go fasterMust go faster
Description
In https://github.com/niklas-heer/speed-comparison we noticed that sum(f, itr; init) is slower than sum(f, itr)
julia> f(n) = sum(i -> 4/(4i-2n-3), 1:n)
f (generic function with 1 method)
julia> g(n) = sum(i -> 4/(4i-2n-3), 1:n; init=0.0)
g (generic function with 1 method)
julia> using BenchmarkTools
julia> @btime f(100_000_000)
217.560 ms (0 allocations: 0 bytes)
3.1415926435897923
julia> @btime g(100_000_000)
398.015 ms (0 allocations: 0 bytes)
3.1415926435899633
julia> versioninfo()
Julia Version 1.9.0-DEV.1600
Commit 392bc97a3a (2022-10-16 17:39 UTC)
Platform Info:
OS: Linux (x86_64-pc-linux-gnu)
CPU: 8 × Intel(R) Core(TM) i7-4870HQ CPU @ 2.50GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-14.0.6 (ORCJIT, haswell)
Threads: 1 on 8 virtual coreswhich is a pity because sum(f, itr; init) can be statically compiled, while sum(f, itr) cannot (because of some internal function throwing).
atthom and PallHaraldsson
Metadata
Metadata
Assignees
Labels
foldsum, maximum, reduce, foldl, etc.sum, maximum, reduce, foldl, etc.performanceMust go fasterMust go faster