| 30 |
ashish |
1 |
#
|
|
|
2 |
# Licensed to the Apache Software Foundation (ASF) under one
|
|
|
3 |
# or more contributor license agreements. See the NOTICE file
|
|
|
4 |
# distributed with this work for additional information
|
|
|
5 |
# regarding copyright ownership. The ASF licenses this file
|
|
|
6 |
# to you under the Apache License, Version 2.0 (the
|
|
|
7 |
# "License"); you may not use this file except in compliance
|
|
|
8 |
# with the License. You may obtain a copy of the License at
|
|
|
9 |
#
|
|
|
10 |
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
11 |
#
|
|
|
12 |
# Unless required by applicable law or agreed to in writing,
|
|
|
13 |
# software distributed under the License is distributed on an
|
|
|
14 |
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
15 |
# KIND, either express or implied. See the License for the
|
|
|
16 |
# specific language governing permissions and limitations
|
|
|
17 |
# under the License.
|
|
|
18 |
#
|
|
|
19 |
|
|
|
20 |
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), *%w[.. .. .. lib rb lib])
|
|
|
21 |
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), *%w[.. .. .. lib rb ext])
|
|
|
22 |
|
|
|
23 |
require 'thrift'
|
|
|
24 |
|
|
|
25 |
require 'benchmark'
|
|
|
26 |
require 'rubygems'
|
|
|
27 |
require 'set'
|
|
|
28 |
require 'pp'
|
|
|
29 |
|
|
|
30 |
# require 'ruby-debug'
|
|
|
31 |
# require 'ruby-prof'
|
|
|
32 |
|
|
|
33 |
require File.join(File.dirname(__FILE__), '../fixtures/structs')
|
|
|
34 |
|
|
|
35 |
transport1 = Thrift::MemoryBuffer.new
|
|
|
36 |
ruby_binary_protocol = Thrift::BinaryProtocol.new(transport1)
|
|
|
37 |
|
|
|
38 |
transport2 = Thrift::MemoryBuffer.new
|
|
|
39 |
c_fast_binary_protocol = Thrift::BinaryProtocolAccelerated.new(transport2)
|
|
|
40 |
|
|
|
41 |
|
|
|
42 |
ooe = Fixtures::Structs::OneOfEach.new
|
|
|
43 |
ooe.im_true = true
|
|
|
44 |
ooe.im_false = false
|
|
|
45 |
ooe.a_bite = -42
|
|
|
46 |
ooe.integer16 = 27000
|
|
|
47 |
ooe.integer32 = 1<<24
|
|
|
48 |
ooe.integer64 = 6000 * 1000 * 1000
|
|
|
49 |
ooe.double_precision = Math::PI
|
|
|
50 |
ooe.some_characters = "Debug THIS!"
|
|
|
51 |
ooe.zomg_unicode = "\xd7\n\a\t"
|
|
|
52 |
|
|
|
53 |
n1 = Fixtures::Structs::Nested1.new
|
|
|
54 |
n1.a_list = []
|
|
|
55 |
n1.a_list << ooe << ooe << ooe << ooe
|
|
|
56 |
n1.i32_map = {}
|
|
|
57 |
n1.i32_map[1234] = ooe
|
|
|
58 |
n1.i32_map[46345] = ooe
|
|
|
59 |
n1.i32_map[-34264] = ooe
|
|
|
60 |
n1.i64_map = {}
|
|
|
61 |
n1.i64_map[43534986783945] = ooe
|
|
|
62 |
n1.i64_map[-32434639875122] = ooe
|
|
|
63 |
n1.dbl_map = {}
|
|
|
64 |
n1.dbl_map[324.65469834] = ooe
|
|
|
65 |
n1.dbl_map[-9458672340.4986798345112] = ooe
|
|
|
66 |
n1.str_map = {}
|
|
|
67 |
n1.str_map['sdoperuix'] = ooe
|
|
|
68 |
n1.str_map['pwoerxclmn'] = ooe
|
|
|
69 |
|
|
|
70 |
n2 = Fixtures::Structs::Nested2.new
|
|
|
71 |
n2.a_list = []
|
|
|
72 |
n2.a_list << n1 << n1 << n1 << n1 << n1
|
|
|
73 |
n2.i32_map = {}
|
|
|
74 |
n2.i32_map[398345] = n1
|
|
|
75 |
n2.i32_map[-2345] = n1
|
|
|
76 |
n2.i32_map[12312] = n1
|
|
|
77 |
n2.i64_map = {}
|
|
|
78 |
n2.i64_map[2349843765934] = n1
|
|
|
79 |
n2.i64_map[-123234985495] = n1
|
|
|
80 |
n2.i64_map[0] = n1
|
|
|
81 |
n2.dbl_map = {}
|
|
|
82 |
n2.dbl_map[23345345.38927834] = n1
|
|
|
83 |
n2.dbl_map[-1232349.5489345] = n1
|
|
|
84 |
n2.dbl_map[-234984574.23498725] = n1
|
|
|
85 |
n2.str_map = {}
|
|
|
86 |
n2.str_map[''] = n1
|
|
|
87 |
n2.str_map['sdflkertpioux'] = n1
|
|
|
88 |
n2.str_map['sdfwepwdcjpoi'] = n1
|
|
|
89 |
|
|
|
90 |
n3 = Fixtures::Structs::Nested3.new
|
|
|
91 |
n3.a_list = []
|
|
|
92 |
n3.a_list << n2 << n2 << n2 << n2 << n2
|
|
|
93 |
n3.i32_map = {}
|
|
|
94 |
n3.i32_map[398345] = n2
|
|
|
95 |
n3.i32_map[-2345] = n2
|
|
|
96 |
n3.i32_map[12312] = n2
|
|
|
97 |
n3.i64_map = {}
|
|
|
98 |
n3.i64_map[2349843765934] = n2
|
|
|
99 |
n3.i64_map[-123234985495] = n2
|
|
|
100 |
n3.i64_map[0] = n2
|
|
|
101 |
n3.dbl_map = {}
|
|
|
102 |
n3.dbl_map[23345345.38927834] = n2
|
|
|
103 |
n3.dbl_map[-1232349.5489345] = n2
|
|
|
104 |
n3.dbl_map[-234984574.23498725] = n2
|
|
|
105 |
n3.str_map = {}
|
|
|
106 |
n3.str_map[''] = n2
|
|
|
107 |
n3.str_map['sdflkertpioux'] = n2
|
|
|
108 |
n3.str_map['sdfwepwdcjpoi'] = n2
|
|
|
109 |
|
|
|
110 |
n4 = Fixtures::Structs::Nested4.new
|
|
|
111 |
n4.a_list = []
|
|
|
112 |
n4.a_list << n3
|
|
|
113 |
n4.i32_map = {}
|
|
|
114 |
n4.i32_map[-2345] = n3
|
|
|
115 |
n4.i64_map = {}
|
|
|
116 |
n4.i64_map[2349843765934] = n3
|
|
|
117 |
n4.dbl_map = {}
|
|
|
118 |
n4.dbl_map[-1232349.5489345] = n3
|
|
|
119 |
n4.str_map = {}
|
|
|
120 |
n4.str_map[''] = n3
|
|
|
121 |
|
|
|
122 |
|
|
|
123 |
# prof = RubyProf.profile do
|
|
|
124 |
# n4.write(c_fast_binary_protocol)
|
|
|
125 |
# Fixtures::Structs::Nested4.new.read(c_fast_binary_protocol)
|
|
|
126 |
# end
|
|
|
127 |
#
|
|
|
128 |
# printer = RubyProf::GraphHtmlPrinter.new(prof)
|
|
|
129 |
# printer.print(STDOUT, :min_percent=>0)
|
|
|
130 |
|
|
|
131 |
Benchmark.bmbm do |x|
|
|
|
132 |
x.report("ruby write large (1MB) structure once") do
|
|
|
133 |
n4.write(ruby_binary_protocol)
|
|
|
134 |
end
|
|
|
135 |
|
|
|
136 |
x.report("ruby read large (1MB) structure once") do
|
|
|
137 |
Fixtures::Structs::Nested4.new.read(ruby_binary_protocol)
|
|
|
138 |
end
|
|
|
139 |
|
|
|
140 |
x.report("c write large (1MB) structure once") do
|
|
|
141 |
n4.write(c_fast_binary_protocol)
|
|
|
142 |
end
|
|
|
143 |
|
|
|
144 |
x.report("c read large (1MB) structure once") do
|
|
|
145 |
Fixtures::Structs::Nested4.new.read(c_fast_binary_protocol)
|
|
|
146 |
end
|
|
|
147 |
|
|
|
148 |
|
|
|
149 |
|
|
|
150 |
x.report("ruby write 10_000 small structures") do
|
|
|
151 |
10_000.times do
|
|
|
152 |
ooe.write(ruby_binary_protocol)
|
|
|
153 |
end
|
|
|
154 |
end
|
|
|
155 |
|
|
|
156 |
x.report("ruby read 10_000 small structures") do
|
|
|
157 |
10_000.times do
|
|
|
158 |
Fixtures::Structs::OneOfEach.new.read(ruby_binary_protocol)
|
|
|
159 |
end
|
|
|
160 |
end
|
|
|
161 |
|
|
|
162 |
x.report("c write 10_000 small structures") do
|
|
|
163 |
10_000.times do
|
|
|
164 |
ooe.write(c_fast_binary_protocol)
|
|
|
165 |
end
|
|
|
166 |
end
|
|
|
167 |
|
|
|
168 |
x.report("c read 10_000 small structures") do
|
|
|
169 |
10_000.times do
|
|
|
170 |
Fixtures::Structs::OneOfEach.new.read(c_fast_binary_protocol)
|
|
|
171 |
end
|
|
|
172 |
end
|
|
|
173 |
|
|
|
174 |
end
|