blob: f1c90d2f75bf74c1ce91fca063707e36a418da0f [file] [log] [blame]
David Reissea2cba82009-03-30 21:35:00 +00001#
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
Bryan Duxburyd815c212009-03-19 18:57:43 +000020require File.dirname(__FILE__) + "/../spec/spec_helper.rb"
Bryan Duxburyd815c212009-03-19 18:57:43 +000021
22require "benchmark"
23# require "ruby-prof"
24
25obj = Fixtures::COMPACT_PROTOCOL_TEST_STRUCT
26
27HOW_MANY = 1_000
28
29binser = Thrift::Serializer.new
30bin_data = binser.serialize(obj)
31bindeser = Thrift::Deserializer.new
32accel_bin_ser = Thrift::Serializer.new(Thrift::BinaryProtocolAcceleratedFactory.new)
33accel_bin_deser = Thrift::Deserializer.new(Thrift::BinaryProtocolAcceleratedFactory.new)
34
35compact_ser = Thrift::Serializer.new(Thrift::CompactProtocolFactory.new)
36compact_data = compact_ser.serialize(obj)
37compact_deser = Thrift::Deserializer.new(Thrift::CompactProtocolFactory.new)
38
39Benchmark.bm(60) do |reporter|
40 reporter.report("binary protocol, write") do
41 HOW_MANY.times do
42 binser.serialize(obj)
43 end
44 end
Dmytro Shteflyukf5c80a42026-03-08 19:09:43 -040045
Bryan Duxburyd815c212009-03-19 18:57:43 +000046 reporter.report("accelerated binary protocol, write") do
47 HOW_MANY.times do
48 accel_bin_ser.serialize(obj)
49 end
50 end
Dmytro Shteflyukf5c80a42026-03-08 19:09:43 -040051
Bryan Duxburyd815c212009-03-19 18:57:43 +000052 reporter.report("compact protocol, write") do
53 # RubyProf.start
54 HOW_MANY.times do
55 compact_ser.serialize(obj)
56 end
57 # result = RubyProf.stop
58 # printer = RubyProf::GraphHtmlPrinter.new(result)
59 # file = File.open("profile.html", "w+")
60 # printer.print(file, 0)
61 # file.close
62 end
Dmytro Shteflyukf5c80a42026-03-08 19:09:43 -040063
Bryan Duxburyd815c212009-03-19 18:57:43 +000064 reporter.report("binary protocol, read") do
65 HOW_MANY.times do
66 bindeser.deserialize(obj, bin_data)
67 end
68 end
Dmytro Shteflyukf5c80a42026-03-08 19:09:43 -040069
Bryan Duxburyd815c212009-03-19 18:57:43 +000070 reporter.report("accelerated binary protocol, read") do
71 HOW_MANY.times do
72 accel_bin_deser.deserialize(obj, bin_data)
73 end
74 end
Dmytro Shteflyukf5c80a42026-03-08 19:09:43 -040075
Bryan Duxburyd815c212009-03-19 18:57:43 +000076 reporter.report("compact protocol, read") do
77 HOW_MANY.times do
78 compact_deser.deserialize(obj, compact_data)
79 end
80 end
81
Bryan Duxburyd815c212009-03-19 18:57:43 +000082 # f = File.new("/tmp/testfile", "w")
Bryan Duxburyd1d15422009-04-04 00:58:03 +000083 # proto = Thrift::BinaryProtocolAccelerated.new(Thrift::IOStreamTransport.new(Thrift::MemoryBufferTransport.new, f))
Bryan Duxburyd815c212009-03-19 18:57:43 +000084 # reporter.report("accelerated binary protocol, write (to disk)") do
85 # HOW_MANY.times do
86 # obj.write(proto)
87 # end
88 # f.flush
89 # end
90 # f.close
Dmytro Shteflyukf5c80a42026-03-08 19:09:43 -040091 #
Bryan Duxburyd815c212009-03-19 18:57:43 +000092 # f = File.new("/tmp/testfile", "r")
Bryan Duxburyd1d15422009-04-04 00:58:03 +000093 # proto = Thrift::BinaryProtocolAccelerated.new(Thrift::IOStreamTransport.new(f, Thrift::MemoryBufferTransport.new))
Bryan Duxburyd815c212009-03-19 18:57:43 +000094 # reporter.report("accelerated binary protocol, read (from disk)") do
95 # HOW_MANY.times do
96 # obj.read(proto)
97 # end
98 # end
99 # f.close
Dmytro Shteflyukf5c80a42026-03-08 19:09:43 -0400100 #
Bryan Duxburyd815c212009-03-19 18:57:43 +0000101 # f = File.new("/tmp/testfile", "w")
102 # reporter.report("compact protocol, write (to disk)") do
Bryan Duxburyd1d15422009-04-04 00:58:03 +0000103 # proto = Thrift::CompactProtocol.new(Thrift::IOStreamTransport.new(Thrift::MemoryBufferTransport.new, f))
Bryan Duxburyd815c212009-03-19 18:57:43 +0000104 # HOW_MANY.times do
105 # obj.write(proto)
106 # end
107 # f.flush
108 # end
109 # f.close
Dmytro Shteflyukf5c80a42026-03-08 19:09:43 -0400110 #
Bryan Duxburyd815c212009-03-19 18:57:43 +0000111 # f = File.new("/tmp/testfile", "r")
112 # reporter.report("compact protocol, read (from disk)") do
Bryan Duxburyd1d15422009-04-04 00:58:03 +0000113 # proto = Thrift::CompactProtocol.new(Thrift::IOStreamTransport.new(f, Thrift::MemoryBufferTransport.new))
Bryan Duxburyd815c212009-03-19 18:57:43 +0000114 # HOW_MANY.times do
115 # obj.read(proto)
116 # end
117 # end
118 # f.close
119
Bryan Duxbury0bbef922009-04-07 22:23:40 +0000120end