# Convex.jl : remarkable increase in perf in dev version (0.13.0) compared to v0.12.6, (now as fast as R/CVXR)

**URL:** <https://discourse.julialang.org/t/convex-jl-remarkable-increase-in-perf-in-dev-version-0-13-0-compared-to-v0-12-6-now-as-fast-as-r-cvxr/31966>\
**Category:** Optimization (Mathematical)\
**Tags:** performance\
**Created:** [December 7, 2019, 12:05pm UTC](https://discourse.julialang.org/t/convex-jl-remarkable-increase-in-perf-in-dev-version-0-13-0-compared-to-v0-12-6-now-as-fast-as-r-cvxr/31966 "2019-12-07T12:05:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![reumle](https://avatars.discourse-cdn.com/v4/letter/r/5daacb/32.png) [@reumle](https://discourse.julialang.org/u/reumle)\
**Post date:** [December 7, 2019, 12:05pm UTC](https://discourse.julialang.org/t/convex-jl-remarkable-increase-in-perf-in-dev-version-0-13-0-compared-to-v0-12-6-now-as-fast-as-r-cvxr/31966/1 "2019-12-07T12:05:40Z")

</div>

The new version performs magnitudes better than its predecessor on the (simple) benchmark described in [Convex.jl (+SCS) more than 100\* slower than R counterpart, CVXR + SCS - #8 by reumle](https://discourse.julialang.org/t/convex-jl-scs-more-than-100-slower-than-r-counterpart-cvxr-scs/31717/8).

This enables me to try problems at least 100 times the size i could do in early december 😃.  
**Great progress!**. Thanks and congratulations to the package maintainer(s)!

- A part of the better performance is the switch to julia 1.3 (cf comment by [ericphanson](https://discourse.julialang.org/u/ericphanson) ,post #9 at that thread).

- Also in the new version, running times are **linear of the problem size** , whereas v0.12.x they increased **quadratically**.

- Perf is now essentially identical to R/CVXR.

### Timings

- `convex.jl` v0.13 , in secs.

```julia-auto
5×5 DataFrame
│ Row │ nCol │ nRow │ moment1 │ setupTm │ solveTm │
│ │ Int64 │ Int64 │ DateTime │ Float64 │ Float64 │
├─────┼───────┼─────────┼─────────────────────────┼─────────┼─────────┤
│ 1 │ 36 │ 10000 │ 2019-12-07T10:22:49.093 │ 0.003 │ 0.641 │
│ 2 │ 36 │ 31600 │ 2019-12-07T10:22:49.737 │ 0.01 │ 1.954 │
│ 3 │ 36 │ 100000 │ 2019-12-07T10:22:51.701 │ 0.037 │ 6.152 │
│ 4 │ 36 │ 316000 │ 2019-12-07T10:22:57.89 │ 0.125 │ 17.738 │
│ 5 │ 36 │ 1000000 │ 2019-12-07T10:23:15.754 │ 0.729 │ 52.752 │

```

- `convex.jl` v0.12.6 (and julia 1.3)
  - Problem sizes here reduced by 10. Timings in that version increase as square of nRow

```julia-auto
julia> df5
5×5 DataFrame
│ Row │ nCol │ nRow │ moment1 │ setupTm │ solveTm │
│ │ Int64 │ Int64 │ DateTime │ Float64 │ Float64 │
├─────┼───────┼────────┼─────────────────────────┼─────────┼─────────┤
│ 1 │ 36 │ 1000 │ 2019-12-07T12:22:15.076 │ 0.0 │ 0.09 │
│ 2 │ 36 │ 3160 │ 2019-12-07T12:22:15.166 │ 0.0 │ 0.486 │
│ 3 │ 36 │ 10000 │ 2019-12-07T12:22:15.652 │ 0.004 │ 3.923 │
│ 4 │ 36 │ 31600 │ 2019-12-07T12:22:19.579 │ 0.011 │ 38.047 │
│ 5 │ 36 │ 100000 │ 2019-12-07T12:22:57.637 │ 0.038 │ 392.442 │

```

- `R/CVXR`

```julia-auto
> df3
# A tibble: 5 x 5
   nCol nRow moment setupTm solveTm
  <dbl> <dbl> <dttm> <dbl> <dbl>
1 36 10000 2019-12-07 10:28:11 0.140 0.792
2 36 31600 2019-12-07 10:28:12 0.131 2.28 
3 36 100000 2019-12-07 10:28:14 0.410 5.94 
4 36 316000 2019-12-07 10:28:21 0.968 17.7  
5 36 1000000 2019-12-07 10:28:39 2.70 55.2  

```

### Code. (v0.13.)

- You need to change 2 lines to run it under v0.12.6. See comments in the code

```julia-auto
using Convex
using SCS
using Random
using Dates
using LinearAlgebra
using DataFrames

df5= DataFrame(nCol = Int64[], nRow= Int64[], moment1=DateTime[], setupTm=Float64[], solveTm=Float64[])

# v0.13
for nRow in [10000,31600,100000,316000,1000000] #different problem sizes
# v0.12 : smaller sizes
# for nRow in [1000,3160,10000,31600,100000] #different problem sizes

  m=nRow
  n=36
  moment1=Dates.now()

  s = Variable(m)

  x = Variable(n); 

  A = randn(m,n)

  b = randn(m)

  p = Problem(:minimize,sum(s), [A*x - b <= s, A*x - b >= -s, x>-10, x< 10, sum(x) >10])
  moment2= Dates.now()
# version 0.13
  solve!(p,SCS.Optimizer( linear_solver= SCS.Direct, max_iters= 10))
# version 0.12
# solve!(p,SCSSolver( linear_solver= SCS.Direct, max_iters= 10))

  #----------------------------------------- 3 solve problem
  moment3= Dates.now()

  #----------------------------------------- 4 collect timings.
  cc=[n,m,moment1,Dates.value(moment2-moment1)/1000,Dates.value(moment3-moment2)/1000]
  push!(df5,cc)
end

```

---

<div class="post-metadata">

**Author:** ![ericphanson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ericphanson/32/215186_2.png) [@ericphanson](https://discourse.julialang.org/u/ericphanson)\
**Post date:** [December 7, 2019, 1:02pm UTC](https://discourse.julialang.org/t/convex-jl-remarkable-increase-in-perf-in-dev-version-0-13-0-compared-to-v0-12-6-now-as-fast-as-r-cvxr/31966/2 "2019-12-07T13:02:13Z")

</div>

That’s great! Very glad to see the performance improvements. In v0.13 we switch the intermediary layer to MathOptInterface, which does most of the hard work and is the product of years of work by its developers. It really shows I think!
