Skip to content

Instantly share code, notes, and snippets.

@mforets
Last active October 27, 2017 09:50
Show Gist options
  • Save mforets/5bcc3e004c34da5f1746c42d73ca20c8 to your computer and use it in GitHub Desktop.
Save mforets/5bcc3e004c34da5f1746c42d73ca20c8 to your computer and use it in GitHub Desktop.
Benchmark of chbv.jl implementations

see PR #16 in Expokit.jl.

data

the different implementations were tested on a fixed set of 8 hermitian negative semidefinite matrices the were randomly generated. the MAT file is available here.

the functions to generate the matrices were:

function test_chbv_real(n::Int, p=0.1)
    D = diagm(-rand(n))
    T = sprandn(n, n, p)
    H = T * D * T'  # random negative semidefinite symmetric matrix
    vec = randn(n)
    return H, vec
end

function test_chbv_complex(n::Int, p=0.1)
    D = diagm(-rand(n))
    T = sprandn(n, n, p) + sprandn(n, n, p)*im
    H = T * D * T.'  # random negative semidefinite hermitian matrix
    vec = randn(n) + randn(n)*im
    return H, vec
end

results with expm

n p type min time (expm) mem (expm) allocs (expm)
100 0.2 real 919.252 μs 3.21 MiB 93
1000 0.2 real 536.044 ms 358.60 MiB 103
100 0.2 complex 4.324 ms 6.57 MiB 247
1000 0.2 complex 1.679 s 732.44 MiB 105
100 0.01 real 782.828 μs 2.83 MiB 83
1000 0.01 real 458.346 ms 320.45 MiB 93
100 0.01 complex 3.534 ms 5.96 MiB 87
1000 0.01 complex 1.711 s 671.41 MiB 97

results: preliminary implementation

n p type min time (chbv) mem (chbv) allocs (chbv)
100 0.2 real 5.571 ms 6.65 MiB 125
1000 0.2 real 1.368 s 663.82 MiB 125
100 0.2 complex 12.628 ms 13.14 MiB 247
1000 0.2 complex 3.105 s 1.28 GiB 247
100 0.01 real 5.639 ms 6.65 MiB 125
1000 0.01 real 1.283 s 663.82 MiB 125
100 0.01 complex 12.595 ms 13.14 MiB 247
1000 0.01 complex 2.921 s 1.28 GiB 247

results: using inplace sums

n p type min time (chbv) mem (chbv) allocs (chbv)
100 0.2 real 4.035 ms 3.32 MiB 95
1000 0.2 real 335.461 ms 328.36 MiB 95
100 0.2 complex 9.532 ms 6.63 MiB 190
1000 0.2 complex 748.766 ms 656.69 MiB 190
100 0.01 real 3.938 ms 3.32 MiB 95
1000 0.01 real 328.811 ms 328.36 MiB 95
100 0.01 complex 9.643 ms 6.63 MiB 190
1000 0.01 complex 799.387 ms 656.69 MiB 190

results: using UnitScaling and merge real parts

n p type min time (chbv) mem (chbv) allocs (chbv)
100 0.2 real 6.424 ms 2.17 MiB 85
1000 0.2 real 475.669 ms 213.96 MiB 85
100 0.2 complex 8.035 ms 4.34 MiB 160
1000 0.2 complex 542.883 ms 427.81 MiB 160
100 0.01 real 3.434 ms 2.17 MiB 85
1000 0.01 real 267.228 ms 213.96 MiB 85
100 0.01 complex 7.910 ms 4.34 MiB 160
1000 0.01 complex 557.828 ms 427.81 MiB 160
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment