Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transition to new CSRMatrix Interface #95

Closed
wants to merge 2 commits into from
Closed

Transition to new CSRMatrix Interface #95

wants to merge 2 commits into from

Conversation

ndinsmore
Copy link

@ndinsmore ndinsmore commented Mar 12, 2019

@ndinsmore
Copy link
Author

Benchmarking code:

using JuMP
using Clp
using GLPK
using BenchmarkTools
using Random
using SparseArrays
using Profile

function  build_model(solver, sp_mat; opt_options::NamedTuple=NamedTuple())
    model = Model(with_optimizer(solver.Optimizer; opt_options...))
    # model = Model(with_optimizer(solver.Optimizer; opt_options...))
    num_variables=size(sp_mat,2)
    # display(Matrix(sp_mat))
    vars=@variable(model,0<=vars[i=1:num_variables]<=0)

    cons=@constraint(model,cons,sp_mat * vars .== 0)
    return model
end
function  build_model_direct(solver, sp_mat; opt_options::NamedTuple=NamedTuple())
    model = JuMP.direct_model(solver.Optimizer( ;opt_options...))
    # model = Model(with_optimizer(solver.Optimizer; opt_options...))
    num_variables=size(sp_mat,2)
    # display(Matrix(sp_mat))
    vars=@variable(model,0<=vars[i=1:num_variables]<=0)

    cons=@constraint(model,cons,sp_mat * vars .== 0)
    return model
end
num_vars=10000
num_cons=10000
density=.001
rng=Random.MersenneTwister(1)
sp_mat=sprand(rng,num_cons,num_vars,density)

direct_build_glpk = @benchmark model=build_model_direct(GLPK,sp_mat)
build_glpk = @benchmark model=build_model(GLPK,$sp_mat)
opt_glpk = @benchmark optimize!(model) setup=(model=build_model(GLPK,$sp_mat))

Master:

julia> direct_build_glpk = @benchmark model=build_model_direct(GLPK,sp_mat)
BenchmarkTools.Trial: 
  memory estimate:  82.20 MiB
  allocs estimate:  778889
  --------------
  minimum time:     172.100 ms (12.63% GC)
  median time:      187.929 ms (17.18% GC)
  mean time:        206.801 ms (24.73% GC)
  maximum time:     313.048 ms (45.21% GC)
  --------------
  samples:          25
  evals/sample:     1

julia> build_glpk = @benchmark model=build_model(GLPK,$sp_mat)
BenchmarkTools.Trial: 
  memory estimate:  30.32 MiB
  allocs estimate:  407356
  --------------
  minimum time:     47.100 ms (0.00% GC)
  median time:      67.214 ms (15.45% GC)
  mean time:        68.707 ms (17.84% GC)
  maximum time:     139.460 ms (63.82% GC)
  --------------
  samples:          73
  evals/sample:     1

julia> opt_glpk = @benchmark optimize!(model) setup=(model=build_model(GLPK,$sp_mat))
BenchmarkTools.Trial: 
  memory estimate:  65.01 MiB
  allocs estimate:  891196
  --------------
  minimum time:     175.015 ms (24.80% GC)
  median time:      228.083 ms (24.67% GC)
  mean time:        247.260 ms (36.24% GC)
  maximum time:     358.414 ms (52.50% GC)
  --------------
  samples:          15
  evals/sample:     1

With above PR:

julia> direct_build_glpk = @benchmark model=build_model_direct(GLPK,sp_mat)
BenchmarkTools.Trial: 
  memory estimate:  82.50 MiB
  allocs estimate:  788889
  --------------
  minimum time:     177.747 ms (17.21% GC)
  median time:      190.433 ms (17.59% GC)
  mean time:        210.528 ms (24.97% GC)
  maximum time:     311.583 ms (42.84% GC)
  --------------
  samples:          24
  evals/sample:     1

julia> build_glpk = @benchmark model=build_model(GLPK,$sp_mat)
BenchmarkTools.Trial: 
  memory estimate:  30.32 MiB
  allocs estimate:  407356
  --------------
  minimum time:     51.908 ms (14.76% GC)
  median time:      76.207 ms (14.56% GC)
  mean time:        80.268 ms (17.78% GC)
  maximum time:     184.978 ms (59.77% GC)
  --------------
  samples:          63
  evals/sample:     1

julia> opt_glpk = @benchmark optimize!(model) setup=(model=build_model(GLPK,$sp_mat))
BenchmarkTools.Trial: 
  memory estimate:  64.93 MiB
  allocs estimate:  891196
  --------------
  minimum time:     193.389 ms (25.18% GC)
  median time:      222.424 ms (26.26% GC)
  mean time:        254.685 ms (36.83% GC)
  maximum time:     348.606 ms (51.62% GC)
  --------------
  samples:          14
  evals/sample:     1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant