blob: 99f07601cd6f8eb329d525202f0db25a4ce9148d [file] [log] [blame]
Kevin Clark4bd89162008-07-08 00:47:49 +00001$LOAD_PATH.unshift File.join(File.dirname(__FILE__), *%w[.. .. .. lib rb lib])
2$LOAD_PATH.unshift File.join(File.dirname(__FILE__), *%w[.. .. .. lib rb ext])
3
4require 'thrift'
5require 'thrift/transport'
6require 'thrift/protocol/binaryprotocol'
7require 'thrift/protocol/binaryprotocolaccelerated'
8
9require 'benchmark'
10require 'rubygems'
11require 'set'
12require 'pp'
13
14# require 'ruby-debug'
15# require 'ruby-prof'
16
17require File.join(File.dirname(__FILE__), '../fixtures/structs')
18
19transport1 = Thrift::MemoryBuffer.new
20ruby_binary_protocol = Thrift::BinaryProtocol.new(transport1)
21
22transport2 = Thrift::MemoryBuffer.new
23c_fast_binary_protocol = Thrift::BinaryProtocolAccelerated.new(transport2)
24
25
26ooe = Fixtures::Structs::OneOfEach.new
27ooe.im_true = true
28ooe.im_false = false
29ooe.a_bite = -42
30ooe.integer16 = 27000
31ooe.integer32 = 1<<24
32ooe.integer64 = 6000 * 1000 * 1000
33ooe.double_precision = Math::PI
34ooe.some_characters = "Debug THIS!"
35ooe.zomg_unicode = "\xd7\n\a\t"
36
37n1 = Fixtures::Structs::Nested1.new
38n1.a_list = []
39n1.a_list << ooe << ooe << ooe << ooe
40n1.i32_map = {}
41n1.i32_map[1234] = ooe
42n1.i32_map[46345] = ooe
43n1.i32_map[-34264] = ooe
44n1.i64_map = {}
45n1.i64_map[43534986783945] = ooe
46n1.i64_map[-32434639875122] = ooe
47n1.dbl_map = {}
48n1.dbl_map[324.65469834] = ooe
49n1.dbl_map[-9458672340.4986798345112] = ooe
50n1.str_map = {}
51n1.str_map['sdoperuix'] = ooe
52n1.str_map['pwoerxclmn'] = ooe
53
54n2 = Fixtures::Structs::Nested2.new
55n2.a_list = []
56n2.a_list << n1 << n1 << n1 << n1 << n1
57n2.i32_map = {}
58n2.i32_map[398345] = n1
59n2.i32_map[-2345] = n1
60n2.i32_map[12312] = n1
61n2.i64_map = {}
62n2.i64_map[2349843765934] = n1
63n2.i64_map[-123234985495] = n1
64n2.i64_map[0] = n1
65n2.dbl_map = {}
66n2.dbl_map[23345345.38927834] = n1
67n2.dbl_map[-1232349.5489345] = n1
68n2.dbl_map[-234984574.23498725] = n1
69n2.str_map = {}
70n2.str_map[''] = n1
71n2.str_map['sdflkertpioux'] = n1
72n2.str_map['sdfwepwdcjpoi'] = n1
73
74n3 = Fixtures::Structs::Nested3.new
75n3.a_list = []
76n3.a_list << n2 << n2 << n2 << n2 << n2
77n3.i32_map = {}
78n3.i32_map[398345] = n2
79n3.i32_map[-2345] = n2
80n3.i32_map[12312] = n2
81n3.i64_map = {}
82n3.i64_map[2349843765934] = n2
83n3.i64_map[-123234985495] = n2
84n3.i64_map[0] = n2
85n3.dbl_map = {}
86n3.dbl_map[23345345.38927834] = n2
87n3.dbl_map[-1232349.5489345] = n2
88n3.dbl_map[-234984574.23498725] = n2
89n3.str_map = {}
90n3.str_map[''] = n2
91n3.str_map['sdflkertpioux'] = n2
92n3.str_map['sdfwepwdcjpoi'] = n2
93
94n4 = Fixtures::Structs::Nested4.new
95n4.a_list = []
96n4.a_list << n3
97n4.i32_map = {}
98n4.i32_map[-2345] = n3
99n4.i64_map = {}
100n4.i64_map[2349843765934] = n3
101n4.dbl_map = {}
102n4.dbl_map[-1232349.5489345] = n3
103n4.str_map = {}
104n4.str_map[''] = n3
105
106
107# prof = RubyProf.profile do
108# n4.write(c_fast_binary_protocol)
109# Fixtures::Structs::Nested4.new.read(c_fast_binary_protocol)
110# end
111#
112# printer = RubyProf::GraphHtmlPrinter.new(prof)
113# printer.print(STDOUT, :min_percent=>0)
114
115Benchmark.bmbm do |x|
116 x.report("ruby write large (1MB) structure once") do
117 n4.write(ruby_binary_protocol)
118 end
119
120 x.report("ruby read large (1MB) structure once") do
121 Fixtures::Structs::Nested4.new.read(ruby_binary_protocol)
122 end
123
124 x.report("c write large (1MB) structure once") do
125 n4.write(c_fast_binary_protocol)
126 end
127
128 x.report("c read large (1MB) structure once") do
129 Fixtures::Structs::Nested4.new.read(c_fast_binary_protocol)
130 end
131
132
133
134 x.report("ruby write 10_000 small structures") do
135 10_000.times do
136 ooe.write(ruby_binary_protocol)
137 end
138 end
139
140 x.report("ruby read 10_000 small structures") do
141 10_000.times do
142 Fixtures::Structs::OneOfEach.new.read(ruby_binary_protocol)
143 end
144 end
145
146 x.report("c write 10_000 small structures") do
147 10_000.times do
148 ooe.write(c_fast_binary_protocol)
149 end
150 end
151
152 x.report("c read 10_000 small structures") do
153 10_000.times do
154 Fixtures::Structs::OneOfEach.new.read(c_fast_binary_protocol)
155 end
156 end
157
158end