Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@joaquimg
Created July 24, 2017 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joaquimg/5dbaf83e7555b94d79f4d01f8ed53119 to your computer and use it in GitHub Desktop.
Save joaquimg/5dbaf83e7555b94d79f4d01f8ed53119 to your computer and use it in GitHub Desktop.
using Xpress
Solver = Xpress

using BenchmarkTools

BenchmarkTools.DEFAULT_PARAMETERS.samples = 100

m1 = Solver.Model()
function add1000vars1(m)
    for i in 1:1000
        Solver.add_cvar!(m, 0.0)  # x
    end
end

m2 = Solver.Model()
function add1000vars2(m)
    Solver.add_cvars!(m, zeros(1000))  # x
    nothing
end
julia> @benchmark add1000vars1(m1)
BenchmarkTools.Trial:
  memory estimate:  484.38 KiB
  allocs estimate:  6000
  --------------
  minimum time:     558.944 μs (0.00% GC)
  median time:      752.458 μs (0.00% GC)
  mean time:        3.825 ms (1.03% GC)
  maximum time:     290.630 ms (0.00% GC)
  --------------
  samples:          100
  evals/sample:     1

julia> @benchmark add1000vars2(m2)
BenchmarkTools.Trial:
  memory estimate:  33.11 KiB
  allocs estimate:  8
  --------------
  minimum time:     55.168 μs (0.00% GC)
  median time:      63.079 μs (0.00% GC)
  mean time:        69.917 μs (0.00% GC)
  maximum time:     136.422 μs (0.00% GC)
  --------------
  samples:          100
  evals/sample:     1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment