<p dir="auto">Hi,</p>
<p dir="auto">I observed a strange effect comparing Timings for an Asian Pricer implementation in Julia 1.4.2 and 1.5 Beta 1.<br>
For the vectorized implementation, Julia 1.5 is significantly faster than Julia 1.4.2 (which is great!).<br>
However, for the loop implementation, it is the other way around - Julia 1.5 took nearly twice as long.</p>
<p dir="auto">Could you please check? Or am I missing something obvious?</p>
<p dir="auto">Thanks and Best Regards<br>
Benjamin</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="using BenchmarkTools
using Random
using Statistics 

T, r, K, s, Xo = promote(1.0, 0.05, 55.0, 0.3, 50) # align types for performance
m, mc = 1000, 10_000

# Source: https://gist.github.com/bkamins/7ecb8bf493cac8d6f6f3c141eedbaf4b

function asian_sample_julia(T, r, K, σ, X₀, m::Integer)
    X = X₀
    x̂ = zero(X)
    Δ = T/m
    for i in 1:m
        X *= exp((r-σ^2/2)*Δ + σ*√Δ*randn())
        x̂ += X
    end
    exp(-r*T)*max(x̂/m - K, 0)
end

function asian_sample_vec_julia(T, r, K, σ, X₀, m::Integer; rng=randn)
    Δ = T/m
    X = rng(typeof(X₀), m)
    X .*= σ*√Δ
    X .+= (r-σ^2/2)*Δ
    X .= exp.(cumsum!(X, X))
    exp(-r*T)*max(mean(X)*X₀ - K, 0)
end

asian_loop_julia(T, r, K, σ, X₀, m::Integer, mc:: Integer, f; kwargs...) = mean(f(T, r, K, σ, X₀, m; kwargs...) for _ in 1:mc)

versioninfo()

println(&quot;Loop implementation:&quot;)
@btime asian_loop_julia($T, $r, $K, $s, $Xo, $m, $mc, $asian_sample_julia)

println(&quot;Vectorized implementation:&quot;)
@btime asian_loop_julia($T, $r, $K, $s, $Xo, $m, $mc, $asian_sample_vec_julia)"><pre class="notranslate"><code class="notranslate">using BenchmarkTools
using Random
using Statistics 

T, r, K, s, Xo = promote(1.0, 0.05, 55.0, 0.3, 50) # align types for performance
m, mc = 1000, 10_000

# Source: https://gist.github.com/bkamins/7ecb8bf493cac8d6f6f3c141eedbaf4b

function asian_sample_julia(T, r, K, σ, X₀, m::Integer)
    X = X₀
    x̂ = zero(X)
    Δ = T/m
    for i in 1:m
        X *= exp((r-σ^2/2)*Δ + σ*√Δ*randn())
        x̂ += X
    end
    exp(-r*T)*max(x̂/m - K, 0)
end

function asian_sample_vec_julia(T, r, K, σ, X₀, m::Integer; rng=randn)
    Δ = T/m
    X = rng(typeof(X₀), m)
    X .*= σ*√Δ
    X .+= (r-σ^2/2)*Δ
    X .= exp.(cumsum!(X, X))
    exp(-r*T)*max(mean(X)*X₀ - K, 0)
end

asian_loop_julia(T, r, K, σ, X₀, m::Integer, mc:: Integer, f; kwargs...) = mean(f(T, r, K, σ, X₀, m; kwargs...) for _ in 1:mc)

versioninfo()

println("Loop implementation:")
@btime asian_loop_julia($T, $r, $K, $s, $Xo, $m, $mc, $asian_sample_julia)

println("Vectorized implementation:")
@btime asian_loop_julia($T, $r, $K, $s, $Xo, $m, $mc, $asian_sample_vec_julia)
</code></pre></div>
<p dir="auto">Output:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Julia Version 1.4.2
Commit 44fa15b150* (2020-05-23 18:35 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: Intel(R) Core(TM) i7-8650U CPU @ 1.90GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-8.0.1 (ORCJIT, skylake)
Environment:
  JULIA_NUM_THREADS = 8
Loop implementation:
  103.978 ms (0 allocations: 0 bytes)
Vectorized implementation:
  165.363 ms (10000 allocations: 77.51 MiB)
2.0182973558431843

Julia Version 1.5.0-beta1.0
Commit 6443f6c95a (2020-05-28 17:42 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: Intel(R) Core(TM) i7-8650U CPU @ 1.90GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-9.0.1 (ORCJIT, skylake)
Environment:
  JULIA_NUM_THREADS = 8
Loop implementation:
  191.175 ms (0 allocations: 0 bytes)
Vectorized implementation:
  115.469 ms (10000 allocations: 77.51 MiB)
2.0806637302421787"><pre class="notranslate"><code class="notranslate">Julia Version 1.4.2
Commit 44fa15b150* (2020-05-23 18:35 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: Intel(R) Core(TM) i7-8650U CPU @ 1.90GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-8.0.1 (ORCJIT, skylake)
Environment:
  JULIA_NUM_THREADS = 8
Loop implementation:
  103.978 ms (0 allocations: 0 bytes)
Vectorized implementation:
  165.363 ms (10000 allocations: 77.51 MiB)
2.0182973558431843

Julia Version 1.5.0-beta1.0
Commit 6443f6c95a (2020-05-28 17:42 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: Intel(R) Core(TM) i7-8650U CPU @ 1.90GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-9.0.1 (ORCJIT, skylake)
Environment:
  JULIA_NUM_THREADS = 8
Loop implementation:
  191.175 ms (0 allocations: 0 bytes)
Vectorized implementation:
  115.469 ms (10000 allocations: 77.51 MiB)
2.0806637302421787
</code></pre></div>
<p dir="auto">This may be a duplicate of <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="17816749" data-permission-text="Title is private" data-url="https://github.com/JuliaLang/julia/issues/3988" data-hovercard-type="issue" data-hovercard-url="/JuliaLang/julia/issues/3988/hovercard" href="https://github.com/JuliaLang/julia/issues/3988">#3988</a>, but this will never be something that users will be able to extend.</p>
<p dir="auto">I'd like to be able to do:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="help?&gt; while
The while loop evaluates the condition expression, and as long it remains true, keeps also evaluating the body of the while loop. If the condition expression is false when the while loop is first reached, the body is never evaluated."><pre class="notranslate"><code class="notranslate">help?&gt; while
The while loop evaluates the condition expression, and as long it remains true, keeps also evaluating the body of the while loop. If the condition expression is false when the while loop is first reached, the body is never evaluated.
</code></pre></div>