-
Notifications
You must be signed in to change notification settings - Fork 101
/
varint_prof.rb
82 lines (72 loc) · 2.17 KB
/
varint_prof.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
75
76
77
78
79
80
81
82
require 'base64'
require 'benchmark/ips'
require 'pry'
require "./spec/support/protos/resource.pb"
#require "jruby/profiler/flame_graph_profile_printer"
VALUES = {
0 => "AA==",
5 => "BQ==",
51 => "Mw==",
9_192 => "6Ec=",
80_389 => "hfQE",
913_389 => "7d83",
516_192_829_912_693 => "9eyMkpivdQ==",
9_999_999_999_999_999_999 => "//+fz8jgyOOKAQ==",
}.freeze
#DECODEME = ::Derp.encode_cache_hash(2576)
#DECODEME2 = ::Derp.encode_cache_hash(25763111)
10_000.times do
t = ::Test::Resource.new(:name => "derp", :date_created => 123456789)
t.status = 3
ss = StringIO.new
::Protobuf::Encoder.encode(t.to_proto, ss)
ss.rewind
t2 = ::Test::Resource.decode_from(ss)
end
if ENV["FLAME"]
result = JRuby::Profiler.profile do
1_000_000.times do
t = ::Test::Resource.new(:name => "derp", :date_created => 123456789)
t.status = 3
ss = StringIO.new
::Protobuf::Encoder.encode(t.to_proto, ss)
ss.rewind
t2 = ::Test::Resource.decode_from(ss)
#fail "derp" unless t == t2
#t = ::Test::Resource.new(:name => "derp", :date_created => 123456789)
#t.field?(:name)
#t.field?(:date_created)
#t.field?(:derp_derp)
#t.respond_to_has_and_present?(:name)
#t.respond_to_has_and_present?(:date_created)
#t.respond_to_has_and_present?(:derp_derp)
end
end
printer = JRuby::Profiler::FlameGraphProfilePrinter.new(result)
printer.printProfile(STDOUT)
else
TO_HASH = ::Test::Resource.new(:name => "derp", :date_created => 123456789)
ENCODE = ::Test::Resource.new(:name => "derp", :date_created => 123456789)
DECODE = begin
ss = StringIO.new
::Protobuf::Encoder.encode(ENCODE.to_proto, ss)
ss.rewind
ss.string
end
Benchmark.ips do |x|
x.config(:time => 20, :warmup => 10)
x.report("to_hash") do
TO_HASH.to_hash
end
x.report("to_hash_with_string_keys") do
TO_HASH.to_hash_with_string_keys
end
x.report("encode") do
ss = StringIO.new
::Protobuf::Encoder.encode(ENCODE.to_proto, ss)
end
x.report("decode") do
::Test::Resource.decode_from(::StringIO.new(DECODE.dup))
end
end
end