---
prelude: |
  require "yaml"
  require "net/imap"

  INPUT_COUNT = Integer ENV.fetch("BENCHMARK_INPUT_COUNT", 1000)
  MAX_INPUT   = Integer ENV.fetch("BENCHMARK_MAX_INPUT",   1400)
  WARMUP_RUNS = Integer ENV.fetch("BENCHMARK_WARMUP_RUNS",  200)

  require "./test/lib/profiling_helper"
  include ProfilingHelper

  SETS = Array.new(1000) {
    Net::IMAP::SequenceSet[Array.new(INPUT_COUNT) { rand(1..MAX_INPUT) }]
  }

  def sets
    l, r = SETS.sample(2)
    [l.dup, r]
  end

  # warmup (esp. for JIT)
  WARMUP_RUNS.times do
    lhs, rhs = sets
    lhs | rhs
    lhs & rhs
    lhs - rhs
    lhs ^ rhs
    ~lhs
  end

benchmark:
  - name:   "intersect?"
    prelude: 'maybe_profile("seqset-intersect-p")'
    script:  l, r = sets; l.intersect? r
  - name: "disjoint?"
    prelude: 'maybe_profile("seqset-disjoint-p")'
    script:  l, r = sets; l.disjoint? r
  - name: "cover?"
    prelude: 'maybe_profile("seqset-cover-p")'
    script:  l, r = sets; l.cover? r

contexts:
  - name: local
    prelude: |
      $LOAD_PATH.unshift "./lib"
      $allowed_to_profile = true # only profile local code
    require: false
  - name: v0.5.9
    gems:
      net-imap: 0.5.9
    require: false
  - name: v0.5.0
    gems:
      net-imap: 0.5.0
    require: false
  - name: v0.4.21
    gems:
      net-imap: 0.4.21
    require: false
