Created
March 22, 2012 05:11
-
-
Save rondale-sc/2156260 to your computer and use it in GitHub Desktop.
playin-with-the-ruby-gc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # './gc_test.rb' | |
| @m = 1000000 | |
| @b = 2 * 5 * (4**3) + 1 | |
| @a = 100001 | |
| def make_fragmentation(h, seed) | |
| i = seed | |
| 10000.times {|m| h << Object.new} | |
| 10000.times do |m| | |
| i = ((@a * i) + @b) % @m | |
| h[i % h.length] = nil | |
| end | |
| end | |
| def run_test | |
| GC::Profiler.enable | |
| heaps = [] | |
| 100.times{|i| make_fragmentation(heaps, i) } | |
| GC::Profiler.result | |
| end | |
| puts run_test |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'bigdecimal' | |
| require 'pp' | |
| output = Hash.new([]) | |
| @totals = {} | |
| path = './gc_test.rb' | |
| 100.times do |test_run| | |
| result_set = `ruby #{path}` # this is where we get the result from the previous script | |
| result_set.split("\n").each_with_index do |result, index| | |
| next if [0,1].include?(index) | |
| result = result.split(" ") | |
| output[result[0]] += [result[5]] | |
| end | |
| end | |
| # This is where we take the cumulative values of the previous 100 results sets by GC cycle | |
| # and grab the average. Big decimal because we want to be precise and the numbers are already | |
| # strings. | |
| output.each do |k,v| | |
| length = BigDecimal.new(v.length.to_s) | |
| nv = v.map! {|i| BigDecimal.new(i)} | |
| @totals[k] = (nv.inject(:+) / length).to_s("F") | |
| end | |
| puts @totals.map{|k,v| v + "\n"} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment