File: comparison.rb

package info (click to toggle)
ruby-benchmark-memory 0.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 300 kB
  • sloc: ruby: 1,121; makefile: 7; sh: 4
file content (40 lines) | stat: -rw-r--r-- 1,181 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# frozen_string_literal: true

module Benchmark
  module Memory
    class Report
      # Compare entries against each other.
      class Comparison
        extend Forwardable

        # Instantiate a new comparison.
        #
        # @param entries [Array<Entry>] The entries to compare.
        # @param comparator [Comparator] The comparator to use when generating.
        def initialize(entries, comparator)
          @entries = entries.sort_by(&comparator)
          @comparator = comparator
        end

        # @return [Comparator] The {Comparator} to use when generating the {Comparison}.
        attr_reader :comparator

        # @return [Array<Entry>] The entries to compare.
        attr_reader :entries

        # @!method metric
        #   @return [Symbol] The metric to compare, one of `:memory`, `:objects`, or `:strings`
        # @!method value
        #   @return [Symbol] The value to compare, one of `:allocated` or `:retained`
        def_delegators :@comparator, :metric, :value

        # Check if the comparison is possible
        #
        # @return [Boolean]
        def possible?
          entries.size > 1
        end
      end
    end
  end
end