Rev 30 | Blame | Compare with Previous | Last modification | View Log | RSS feed
## Licensed to the Apache Software Foundation (ASF) under one# or more contributor license agreements. See the NOTICE file# distributed with this work for additional information# regarding copyright ownership. The ASF licenses this file# to you under the Apache License, Version 2.0 (the# "License"); you may not use this file except in compliance# with the License. You may obtain a copy of the License at## http://www.apache.org/licenses/LICENSE-2.0## Unless required by applicable law or agreed to in writing,# software distributed under the License is distributed on an# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY# KIND, either express or implied. See the License for the# specific language governing permissions and limitations# under the License.#$LOAD_PATH.unshift File.join(File.dirname(__FILE__), *%w[.. .. .. lib rb lib])$LOAD_PATH.unshift File.join(File.dirname(__FILE__), *%w[.. .. .. lib rb ext])require 'thrift'require 'benchmark'require 'rubygems'require 'set'require 'pp'# require 'ruby-debug'# require 'ruby-prof'require File.join(File.dirname(__FILE__), '../fixtures/structs')transport1 = Thrift::MemoryBuffer.newruby_binary_protocol = Thrift::BinaryProtocol.new(transport1)transport2 = Thrift::MemoryBuffer.newc_fast_binary_protocol = Thrift::BinaryProtocolAccelerated.new(transport2)ooe = Fixtures::Structs::OneOfEach.newooe.im_true = trueooe.im_false = falseooe.a_bite = -42ooe.integer16 = 27000ooe.integer32 = 1<<24ooe.integer64 = 6000 * 1000 * 1000ooe.double_precision = Math::PIooe.some_characters = "Debug THIS!"ooe.zomg_unicode = "\xd7\n\a\t"n1 = Fixtures::Structs::Nested1.newn1.a_list = []n1.a_list << ooe << ooe << ooe << ooen1.i32_map = {}n1.i32_map[1234] = ooen1.i32_map[46345] = ooen1.i32_map[-34264] = ooen1.i64_map = {}n1.i64_map[43534986783945] = ooen1.i64_map[-32434639875122] = ooen1.dbl_map = {}n1.dbl_map[324.65469834] = ooen1.dbl_map[-9458672340.4986798345112] = ooen1.str_map = {}n1.str_map['sdoperuix'] = ooen1.str_map['pwoerxclmn'] = ooen2 = Fixtures::Structs::Nested2.newn2.a_list = []n2.a_list << n1 << n1 << n1 << n1 << n1n2.i32_map = {}n2.i32_map[398345] = n1n2.i32_map[-2345] = n1n2.i32_map[12312] = n1n2.i64_map = {}n2.i64_map[2349843765934] = n1n2.i64_map[-123234985495] = n1n2.i64_map[0] = n1n2.dbl_map = {}n2.dbl_map[23345345.38927834] = n1n2.dbl_map[-1232349.5489345] = n1n2.dbl_map[-234984574.23498725] = n1n2.str_map = {}n2.str_map[''] = n1n2.str_map['sdflkertpioux'] = n1n2.str_map['sdfwepwdcjpoi'] = n1n3 = Fixtures::Structs::Nested3.newn3.a_list = []n3.a_list << n2 << n2 << n2 << n2 << n2n3.i32_map = {}n3.i32_map[398345] = n2n3.i32_map[-2345] = n2n3.i32_map[12312] = n2n3.i64_map = {}n3.i64_map[2349843765934] = n2n3.i64_map[-123234985495] = n2n3.i64_map[0] = n2n3.dbl_map = {}n3.dbl_map[23345345.38927834] = n2n3.dbl_map[-1232349.5489345] = n2n3.dbl_map[-234984574.23498725] = n2n3.str_map = {}n3.str_map[''] = n2n3.str_map['sdflkertpioux'] = n2n3.str_map['sdfwepwdcjpoi'] = n2n4 = Fixtures::Structs::Nested4.newn4.a_list = []n4.a_list << n3n4.i32_map = {}n4.i32_map[-2345] = n3n4.i64_map = {}n4.i64_map[2349843765934] = n3n4.dbl_map = {}n4.dbl_map[-1232349.5489345] = n3n4.str_map = {}n4.str_map[''] = n3# prof = RubyProf.profile do# n4.write(c_fast_binary_protocol)# Fixtures::Structs::Nested4.new.read(c_fast_binary_protocol)# end## printer = RubyProf::GraphHtmlPrinter.new(prof)# printer.print(STDOUT, :min_percent=>0)Benchmark.bmbm do |x|x.report("ruby write large (1MB) structure once") don4.write(ruby_binary_protocol)endx.report("ruby read large (1MB) structure once") doFixtures::Structs::Nested4.new.read(ruby_binary_protocol)endx.report("c write large (1MB) structure once") don4.write(c_fast_binary_protocol)endx.report("c read large (1MB) structure once") doFixtures::Structs::Nested4.new.read(c_fast_binary_protocol)endx.report("ruby write 10_000 small structures") do10_000.times doooe.write(ruby_binary_protocol)endendx.report("ruby read 10_000 small structures") do10_000.times doFixtures::Structs::OneOfEach.new.read(ruby_binary_protocol)endendx.report("c write 10_000 small structures") do10_000.times doooe.write(c_fast_binary_protocol)endendx.report("c read 10_000 small structures") do10_000.times doFixtures::Structs::OneOfEach.new.read(c_fast_binary_protocol)endendend