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
|
# File 'lib/benchmark/sweet/memory.rb', line 4
def run_memory
require 'memory_profiler'
puts "Memory Profiling----------" unless quiet?
items.each do |entry|
name = entry.label
$stdout.printf("%20s ", name.to_s) unless quiet?
rpts = (options[:memory] || 1).times.map { MemoryProfiler.report(&entry.block) }
tot_stat = add_entry(name, "memsize", rpts.map(&:total_allocated_memsize))
totr_stat = add_entry name, "memsize_retained", rpts.map(&:total_retained_memsize)
obj_stat = add_entry name, "objects", rpts.map(&:total_allocated) objr_stat = add_entry name, "objects_retained", rpts.map(&:total_retained)
str_stat = add_entry(name, "strings", rpts.map { |rpt| rpt.strings_allocated.size })
strr_stat = add_entry(name, "strings_retained", rpts.map { |rpt| rpt.strings_retained.size })
$stdout.printf("%10s alloc/ret %10s strings/ret\n",
"#{tot_stat.central_tendency}/#{totr_stat.central_tendency}",
"#{str_stat.central_tendency}/#{strr_stat.central_tendency}") unless quiet?
end
end
|