Project

General

Profile

bm_gc_fragmentation.rb

authorNari (Narihiro Nakamura), 04/27/2010 01:11 AM

Download (445 Bytes)

 
1
# Make pseudo flagmentation in a ruby objects heap.
2
GC::Profiler.enable if $DEBUG
3

    
4
M = 1000000
5
B = 2 * 5 * (4**3) + 1
6
A = 100001
7

    
8
def make_fragmentation(h, seed)
9
  i = seed
10
  10000.times {|m|
11
    h << Object.new
12
  }
13
  10000.times {|m|
14
    i = ((A * i) + B) % M
15
    h[i % h.length] = nil
16
  }
17
end
18

    
19
heaps = []
20
100.times{|i| make_fragmentation(heaps, i) }
21

    
22
if $DEBUG
23
  GC::Profiler.report
24
  puts GC::Profiler.total_time
25
end