blob: 1e1f08f010c2b323711ff646cb9f56af8f2743a6 [file] [log] [blame]
Bryan Duxburyd815c212009-03-19 18:57:43 +00001require File.dirname(__FILE__) + "/../spec/spec_helper.rb"
2require "lib/thrift/serializer"
3require "lib/thrift/protocol/binaryprotocolaccelerated"
4
5require "benchmark"
6# require "ruby-prof"
7
8obj = Fixtures::COMPACT_PROTOCOL_TEST_STRUCT
9
10HOW_MANY = 1_000
11
12binser = Thrift::Serializer.new
13bin_data = binser.serialize(obj)
14bindeser = Thrift::Deserializer.new
15accel_bin_ser = Thrift::Serializer.new(Thrift::BinaryProtocolAcceleratedFactory.new)
16accel_bin_deser = Thrift::Deserializer.new(Thrift::BinaryProtocolAcceleratedFactory.new)
17
18compact_ser = Thrift::Serializer.new(Thrift::CompactProtocolFactory.new)
19compact_data = compact_ser.serialize(obj)
20compact_deser = Thrift::Deserializer.new(Thrift::CompactProtocolFactory.new)
21
22Benchmark.bm(60) do |reporter|
23 reporter.report("binary protocol, write") do
24 HOW_MANY.times do
25 binser.serialize(obj)
26 end
27 end
28
29 reporter.report("accelerated binary protocol, write") do
30 HOW_MANY.times do
31 accel_bin_ser.serialize(obj)
32 end
33 end
34
35 reporter.report("compact protocol, write") do
36 # RubyProf.start
37 HOW_MANY.times do
38 compact_ser.serialize(obj)
39 end
40 # result = RubyProf.stop
41 # printer = RubyProf::GraphHtmlPrinter.new(result)
42 # file = File.open("profile.html", "w+")
43 # printer.print(file, 0)
44 # file.close
45 end
46
47 reporter.report("binary protocol, read") do
48 HOW_MANY.times do
49 bindeser.deserialize(obj, bin_data)
50 end
51 end
52
53 reporter.report("accelerated binary protocol, read") do
54 HOW_MANY.times do
55 accel_bin_deser.deserialize(obj, bin_data)
56 end
57 end
58
59 reporter.report("compact protocol, read") do
60 HOW_MANY.times do
61 compact_deser.deserialize(obj, compact_data)
62 end
63 end
64
65
66 # f = File.new("/tmp/testfile", "w")
67 # proto = Thrift::BinaryProtocolAccelerated.new(Thrift::IOStreamTransport.new(Thrift::MemoryBuffer.new, f))
68 # reporter.report("accelerated binary protocol, write (to disk)") do
69 # HOW_MANY.times do
70 # obj.write(proto)
71 # end
72 # f.flush
73 # end
74 # f.close
75 #
76 # f = File.new("/tmp/testfile", "r")
77 # proto = Thrift::BinaryProtocolAccelerated.new(Thrift::IOStreamTransport.new(f, Thrift::MemoryBuffer.new))
78 # reporter.report("accelerated binary protocol, read (from disk)") do
79 # HOW_MANY.times do
80 # obj.read(proto)
81 # end
82 # end
83 # f.close
84 #
85 # f = File.new("/tmp/testfile", "w")
86 # reporter.report("compact protocol, write (to disk)") do
87 # proto = Thrift::CompactProtocol.new(Thrift::IOStreamTransport.new(Thrift::MemoryBuffer.new, f))
88 # HOW_MANY.times do
89 # obj.write(proto)
90 # end
91 # f.flush
92 # end
93 # f.close
94 #
95 # f = File.new("/tmp/testfile", "r")
96 # reporter.report("compact protocol, read (from disk)") do
97 # proto = Thrift::CompactProtocol.new(Thrift::IOStreamTransport.new(f, Thrift::MemoryBuffer.new))
98 # HOW_MANY.times do
99 # obj.read(proto)
100 # end
101 # end
102 # f.close
103
104end