This repository has been archived by the owner on Jun 29, 2023. It is now read-only.
forked from rubyamf/rocketamf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
benchmark.rb
74 lines (66 loc) · 1.97 KB
/
benchmark.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
$:.unshift(File.dirname(__FILE__) + '/ext')
$:.unshift(File.dirname(__FILE__) + '/lib')
require 'rubygems'
require 'rocketamf'
require 'rocketamf/pure/deserializer' # Only ext gets included by default if available
require 'rocketamf/pure/serializer'
OBJECT_COUNT = 100000
TESTS = 5
class TestClass
attr_accessor :prop_a, :prop_b, :prop_c, :prop_d, :prop_e
def populate some_arg=nil # Make sure class mapper doesn't think populate is a property
@@count ||= 1
@prop_a = "asdfasdf #{@@count}"
@prop_b = "simple string"
@prop_c = 3120094.03
@prop_d = Time.now
@prop_e = 3120094
@@count += 1
self
end
end
objs = []
OBJECT_COUNT.times do
objs << TestClass.new.populate
end
["native", "pure"].each do |type|
# Set up class mapper
cm = if type == "pure"
RocketAMF::ClassMapping
else
RocketAMF::Ext::FastClassMapping
end
cm.define do |m|
m.map :as => 'TestClass', :ruby => 'TestClass'
end
[0, 3].each do |version|
# 2**24 is larger than anyone is ever going to run this for
min_serialize = 2**24
min_deserialize = 2**24
puts "Testing #{type} AMF#{version}:"
TESTS.times do
ser = if type == "pure"
RocketAMF::Pure::Serializer.new(cm.new)
else
RocketAMF::Ext::Serializer.new(cm.new)
end
start_time = Time.now
out = ser.serialize(version, objs)
end_time = Time.now
puts "\tserialize run: #{end_time-start_time}s"
min_serialize = [end_time-start_time, min_serialize].min
des = if type == "pure"
RocketAMF::Pure::Deserializer.new(cm.new)
else
RocketAMF::Ext::Deserializer.new(cm.new)
end
start_time = Time.now
temp = des.deserialize(version, out)
end_time = Time.now
puts "\tdeserialize run: #{end_time-start_time}s"
min_deserialize = [end_time-start_time, min_deserialize].min
end
puts "\tminimum serialize time: #{min_serialize}s"
puts "\tminimum deserialize time: #{min_deserialize}s"
end
end