class Benchmark::Malloc::AllocationSet

Attributes

allocations[R]

Public Class Methods

new(allocations) click to toggle source
# File lib/benchmark/malloc/allocation_set.rb, line 10
def initialize(allocations)
  @allocations = allocations
end

Public Instance Methods

count_memory() click to toggle source

@api public

# File lib/benchmark/malloc/allocation_set.rb, line 37
def count_memory
  @allocations.
    map { |alloc| [alloc.object.class, alloc.memsize] }.
    each_with_object(Hash.new(0)) { |(name, mem), h| h[name] += mem }
end
count_objects() click to toggle source

@api public

# File lib/benchmark/malloc/allocation_set.rb, line 30
def count_objects
  @allocations.
    map { |alloc| alloc.object.class }.
    each_with_object(Hash.new(0)) { |name, h| h[name] += 1 }
end
each(&block) click to toggle source
# File lib/benchmark/malloc/allocation_set.rb, line 14
def each(&block)
  return to_enum(:each) unless block
  @allocations.each(&block)
end
filter(*class_names) click to toggle source
# File lib/benchmark/malloc/allocation_set.rb, line 43
def filter(*class_names)
  @allocations.
    select { |alloc| class_names.include?(alloc.object.class) }
end
total_memory() click to toggle source

@api public

# File lib/benchmark/malloc/allocation_set.rb, line 25
def total_memory
  @allocations.reduce(0) { |acc, alloc| acc + alloc.memsize }
end
total_objects() click to toggle source

@api public

# File lib/benchmark/malloc/allocation_set.rb, line 20
def total_objects
  @allocations.size
end