Skip to content

Creating binary variables is slow #1255

@mlubin

Description

@mlubin
using JuMP
using BenchmarkTools

function with_bin(N)
    model = Model()
    x = @variable(model, [1:N], Bin)
    return x
end

function without_bin(N)
    model = Model()
    x = @variable(model, [1:N])
    return x
end

@btime with_bin(1_000_000)
@btime without_bin(1_000_000)

JuMP master, Julia 1.0.1:

  930.520 ms (6000340 allocations: 950.56 MiB)
  184.530 ms (2000252 allocations: 87.93 MiB)

JuMP 0.18, Julia 1.0.1:

  60.050 ms (1000168 allocations: 79.79 MiB)
  102.381 ms (1000168 allocations: 79.79 MiB)

(don't ask me to explain why binary variables are created faster than nonbinary variables on 0.18, it's very weird).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions