-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathwrapper.rb
39 lines (31 loc) · 816 Bytes
/
wrapper.rb
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
require 'json'
require 'benchmark'
require 'ap'
def measure(&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_stats_before = GC.stat
time = Benchmark.realtime do
yield
end
puts "Objects: #{ObjectSpace.count_objects}"
unless no_gc
GC.start(full_mark: true, immediate_sweep: true, immediate_mark: false)
puts "Objects after GC: #{ObjectSpace.count_objects}"
end
gc_stats_after = GC.stat
memory_after = `ps -o rss= -p #{Process.pid}`.to_i/1024
ap({
RUBY_VERSION => {
gc: no_gc ? 'disabled' : 'enabled',
time: time.round(2),
gc_count: gc_stats_after[:count] - gc_stats_before[:count],
memory: "%d MB" % (memory_after - memory_before)
}
})
end