Sha256: b590d479d5165c96ca555106270d7ae1ba10321227b3c34642fa173979589b67

Contents?: true

Size: 1.37 KB

Versions: 8

Compression:

Stored size: 1.37 KB

Contents

require 'benchmark'
require 'solve'
require 'solve/gecode_solver'
require File.expand_path("../large_graph_no_solution", __FILE__)
require File.expand_path("../opscode_ci_graph", __FILE__)

PROBLEM = OpscodeCiGraph
#PROBLEM = LargeGraphNoSolution
N = 100

def demands
  PROBLEM::DEMANDS
end

def artifacts
  PROBLEM::ARTIFACTS
end

require 'pp'

def create_graph
  graph = Solve::Graph.new
  artifacts.each do |name, all_artifact_versions|
    all_artifact_versions.each do |artifact|
      graph.artifact(name, artifact[:version])
      artifact[:dependencies].each do |dep|
        dep_name, dep_constraint = dep
        graph.artifact(name, artifact[:version])
          .depends(dep_name, dep_constraint)
      end
    end
  end

  graph
end

STATIC_GRAPH = create_graph

def solve_gecode
  Solve::GecodeSolver.new(STATIC_GRAPH, demands).resolve({})
rescue Solve::Errors::NoSolutionError => e
  # Uncomment to look at the error messages. Probably only useful if N == 1
  #puts e
  e
end

def solve_ruby
  Solve::RubySolver.new(STATIC_GRAPH, demands).resolve({})
rescue Solve::Errors::NoSolutionError => e
  # Uncomment to look at the error messages. Probably only useful if N == 1
  #puts e
  e
end

Benchmark.bm(12) do |x|
  x.report("Create graph")   { N.times { create_graph } }
  x.report("Solve Gecode") { N.times { solve_gecode } }
  x.report("Solve Ruby") { N.times { solve_ruby } }
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
solve-3.1.1 spec/acceptance/benchmark.rb
solve-3.1.0 spec/acceptance/benchmark.rb
solve-3.0.1 spec/acceptance/benchmark.rb
solve-3.0.0 spec/acceptance/benchmark.rb
solve-2.0.3 spec/acceptance/benchmark.rb
solve-2.0.2 spec/acceptance/benchmark.rb
solve-2.0.1 spec/acceptance/benchmark.rb
solve-2.0.0 spec/acceptance/benchmark.rb