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
|
# File 'lib/beasure.rb', line 5
def self.perform(&block)
no_gc = (ARGV[0] == "--no-gc")
if no_gc
GC.disable
else
GC.start
end
memory_before = `ps -o rss= -p #{Process.pid}`.to_i / 1024
gc_stat_before = GC.stat
time = Benchmark.realtime do
yield
end
GC.start(full_mark: true, immediate_sweep: true, immediate_mark: false) unless no_gc
gc_stat_after = GC.stat
memory_after = `ps -o rss= -p #{Process.pid}`.to_i / 1024
puts("*******************************************************")
puts("Ruby Version: #{RUBY_VERSION}")
puts("Execution Time: #{time.round(2)}")
puts("Garbage Collection Infos:")
puts(" Usage: #{no_gc ? 'disabled' : 'enabled'}")
puts(" Counter: #{gc_stat_after[:count] - gc_stat_before[:count]}")
puts(" Memory: #{'%d MB' % (memory_after - memory_before)}")
puts("*******************************************************")
end
|