Caching is faster, but it's not thaaaat much faster.
This would simplify a lot of the code:
julia> import Xpress_jll
julia> ENV["XPAUTH_PATH"] = "/Users/odow/git/jump-dev/Xpress/xpauth.xpr"
"/Users/odow/git/jump-dev/Xpress/xpauth.xpr"
julia> ENV["XPRESS_JL_LIBRARY"] = Xpress_jll.libxprs
"/Users/odow/.julia/artifacts/de1f33df0ad1d3821c28981f866e70c548b30efd/lib/libxprs.dylib"
julia> using JuMP, Xpress
julia> function build_prob(N)
model = direct_model(Xpress.Optimizer())
set_silent(model)
@variable(model, x[1:N], Bin)
@constraint(model, rand(N)' * x <= 0.1 * N)
@objective(model, Max, rand(N)' * x)
optimize!(model)
return backend(model)
end
build_prob (generic function with 1 method)
julia> function get_cached(prob, N)
solstatusP = Ref{Cint}()
cache = zeros(Cdouble, N)
@assert XPRSgetsolution(prob, solstatusP, cache, 0, N - 1) == 0
return cache
end
get_cached (generic function with 1 method)
julia> function get_iter(prob, N)
solstatusP = Ref{Cint}()
cache = zeros(Cdouble, N)
cacheP = Ref{Cdouble}()
for i in 1:N
@assert XPRSgetsolution(prob, solstatusP, cacheP, i-1, i-1) == 0
cache[i] = cacheP[]
end
return cache
end
get_iter (generic function with 1 method)
julia> function main(N)
prob = build_prob(N)
@time a = get_cached(prob, N)
@time b = get_iter(prob, N)
@assert a == b
return
end
main (generic function with 1 method)
julia> main(100)
0.005504 seconds (8.31 k allocations: 402.859 KiB, 99.62% compilation time)
0.006516 seconds (10.23 k allocations: 527.172 KiB, 97.79% compilation time)
julia> main(100)
0.000024 seconds (2 allocations: 928 bytes)
0.000355 seconds (2 allocations: 928 bytes)
julia> main(1000)
0.000033 seconds (4 allocations: 8.078 KiB)
0.017494 seconds (4 allocations: 8.078 KiB)
julia> main(10000)
0.000018 seconds (4 allocations: 96.078 KiB)
0.001619 seconds (4 allocations: 96.078 KiB)
julia> main(100000)
0.000025 seconds (4 allocations: 800.078 KiB)
0.007707 seconds (4 allocations: 800.078 KiB)
julia> main(1000000)
0.000391 seconds (4 allocations: 7.656 MiB)
0.079414 seconds (4 allocations: 7.656 MiB)
Caching is faster, but it's not thaaaat much faster.
This would simplify a lot of the code: