Skip to content

Potential Performance regression between Julia 1.4.2 and 1.5 Beta 1 #36414

Closed
@lungben

Description

@lungben

Hi,

I observed a strange effect comparing Timings for an Asian Pricer implementation in Julia 1.4.2 and 1.5 Beta 1.
For the vectorized implementation, Julia 1.5 is significantly faster than Julia 1.4.2 (which is great!).
However, for the loop implementation, it is the other way around - Julia 1.5 took nearly twice as long.

Could you please check? Or am I missing something obvious?

Thanks and Best Regards
Benjamin

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)

Output:

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    performanceMust go fasterrandomnessRandom number generation and the Random stdlibregressionRegression in behavior compared to a previous version

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions