Top Level Namespace
Defined Under Namespace
Modules: BinData
Classes: Test1, Test2, Test3, Test4
Constant Summary
collapse
- COUNT =
50000
Instance Method Summary
collapse
Instance Method Details
#prof(&block) ⇒ Object
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/bench.rb', line 85
def prof(&block)
require 'rubygems'
require 'ruby-prof'
result = RubyProf.profile do
block.call
end
printer = RubyProf::GraphPrinter.new(result)
printer.print(STDOUT, 0)
end
|
#test1(klass) ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/bench.rb', line 37
def test1(klass)
a = Time.now
z = []
COUNT.times do
obj = klass.new
z << obj
end
b = Time.now
puts "#{klass}: #{b - a}"
end
|
#test2 ⇒ Object
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/bench.rb', line 51
def test2
a = Time.now
z = []
COUNT.times do |i|
eval <<-END
class A#{i} < BinData::Record
int8 :a
int8 :b
int8 :c
int8 :d
int8 :e
int8 :f
int8 :g
int8 :h
int8 :i
int8 :j
int8 :k
int8 :l
int8 :m
int8 :n
int8 :o
int8 :p
int8 :q
int8 :r
int8 :s
int8 :t
end
END
end
b = Time.now
puts "test2: #{b - a}"
end
|