Project

General

Profile

Feature #2328 » test.rb

wanabe (_ wanabe), 11/04/2009 09:01 PM

 
1
require 'benchmark'
2

    
3
type = ARGV[0]
4
memory_size = 200
5
obj_num = 2000
6

    
7
case type
8
when /^m/
9
  print "malloc "
10
  10.times do |i|
11
    print "."
12
    " " * (1024 * 1024 * memory_size)
13
  end
14
else
15
  print "realloc "
16
  10.times do |i|
17
    print "."
18
    a = []
19
    (memory_size*1024).times do
20
      a[1024] = nil
21
      a.clear
22
    end
23
  end
24
end
25

    
26
puts " start benchmark", ""
27
GC::Profiler.enable
28

    
29
Benchmark.bm do |bm|
30
  bm.report do
31
    obj_num.times do
32
      " " * (1024*1024)
33
    end
34
  end
35
end
36

    
37
puts "", GC::Profiler.result[/.+\n/]