msgpack 1.4.2 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yaml +57 -0
- data/ChangeLog +60 -0
- data/README.md +25 -1
- data/Rakefile +1 -2
- data/bench/bench.rb +78 -0
- data/bin/console +8 -0
- data/doclib/msgpack/factory.rb +47 -3
- data/doclib/msgpack/packer.rb +5 -4
- data/doclib/msgpack/unpacker.rb +2 -2
- data/ext/java/org/msgpack/jruby/Buffer.java +23 -16
- data/ext/java/org/msgpack/jruby/Decoder.java +29 -21
- data/ext/java/org/msgpack/jruby/Encoder.java +68 -30
- data/ext/java/org/msgpack/jruby/ExtensionRegistry.java +37 -49
- data/ext/java/org/msgpack/jruby/ExtensionValue.java +5 -8
- data/ext/java/org/msgpack/jruby/Factory.java +47 -7
- data/ext/java/org/msgpack/jruby/Packer.java +29 -17
- data/ext/java/org/msgpack/jruby/Unpacker.java +66 -42
- data/ext/msgpack/buffer.c +38 -57
- data/ext/msgpack/buffer.h +19 -10
- data/ext/msgpack/buffer_class.c +90 -52
- data/ext/msgpack/compat.h +0 -99
- data/ext/msgpack/extconf.rb +9 -22
- data/ext/msgpack/factory_class.c +133 -43
- data/ext/msgpack/packer.c +60 -36
- data/ext/msgpack/packer.h +27 -18
- data/ext/msgpack/packer_class.c +84 -77
- data/ext/msgpack/packer_class.h +11 -0
- data/ext/msgpack/packer_ext_registry.c +24 -32
- data/ext/msgpack/packer_ext_registry.h +40 -33
- data/ext/msgpack/sysdep.h +5 -2
- data/ext/msgpack/unpacker.c +128 -97
- data/ext/msgpack/unpacker.h +17 -10
- data/ext/msgpack/unpacker_class.c +75 -80
- data/ext/msgpack/unpacker_class.h +11 -0
- data/ext/msgpack/unpacker_ext_registry.c +42 -18
- data/ext/msgpack/unpacker_ext_registry.h +23 -16
- data/lib/msgpack/bigint.rb +69 -0
- data/lib/msgpack/factory.rb +103 -0
- data/lib/msgpack/symbol.rb +21 -4
- data/lib/msgpack/time.rb +1 -1
- data/lib/msgpack/version.rb +1 -1
- data/lib/msgpack.rb +5 -7
- data/msgpack.gemspec +2 -2
- data/spec/bigint_spec.rb +26 -0
- data/spec/cruby/buffer_spec.rb +17 -0
- data/spec/factory_spec.rb +351 -12
- data/spec/msgpack_spec.rb +1 -1
- data/spec/packer_spec.rb +18 -0
- data/spec/spec_helper.rb +20 -3
- data/spec/timestamp_spec.rb +38 -0
- data/spec/unpacker_spec.rb +54 -4
- metadata +25 -41
- data/.travis.yml +0 -39
- data/bench/pack.rb +0 -23
- data/bench/pack_log.rb +0 -33
- data/bench/pack_log_long.rb +0 -65
- data/bench/pack_symbols.rb +0 -28
- data/bench/run.sh +0 -14
- data/bench/run_long.sh +0 -35
- data/bench/run_symbols.sh +0 -26
- data/bench/unpack.rb +0 -21
- data/bench/unpack_log.rb +0 -34
- data/bench/unpack_log_long.rb +0 -67
data/spec/packer_spec.rb
CHANGED
@@ -488,6 +488,24 @@ describe MessagePack::Packer do
|
|
488
488
|
it { is_expected.to eq "\xC7\x0F\x01value_msgpacked" }
|
489
489
|
end
|
490
490
|
|
491
|
+
shared_examples_for 'extension subclasses core type' do |klass|
|
492
|
+
before { stub_const('Value', Class.new(klass)) }
|
493
|
+
let(:object) { Value.new }
|
494
|
+
subject { packer.pack(object).to_s }
|
495
|
+
|
496
|
+
it "defaults to #{klass.name} packer if no extension is present" do
|
497
|
+
expect(subject).to eq(MessagePack.dump(klass.new))
|
498
|
+
end
|
499
|
+
|
500
|
+
it "uses core type extension for #{klass.name}" do
|
501
|
+
packer.register_type(0x01, Value, ->(_) { 'value_msgpacked' })
|
502
|
+
expect(subject).to eq("\xC7\x0F\x01value_msgpacked")
|
503
|
+
end
|
504
|
+
end
|
505
|
+
it_behaves_like 'extension subclasses core type', Hash
|
506
|
+
it_behaves_like 'extension subclasses core type', Array
|
507
|
+
it_behaves_like 'extension subclasses core type', String
|
508
|
+
|
491
509
|
context 'when registering a type for symbols' do
|
492
510
|
before { packer.register_type(0x00, ::Symbol, :to_msgpack_ext) }
|
493
511
|
|
data/spec/spec_helper.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require "set"
|
2
|
+
require "objspace"
|
1
3
|
|
2
4
|
if ENV['SIMPLE_COV']
|
3
5
|
require 'simplecov'
|
@@ -14,11 +16,26 @@ if ENV['GC_STRESS']
|
|
14
16
|
end
|
15
17
|
|
16
18
|
require 'msgpack'
|
19
|
+
require "msgpack/bigint"
|
17
20
|
|
18
|
-
|
19
|
-
|
21
|
+
if GC.respond_to?(:verify_compaction_references)
|
22
|
+
# This method was added in Ruby 3.0.0. Calling it this way asks the GC to
|
23
|
+
# move objects around, helping to find object movement bugs.
|
24
|
+
begin
|
25
|
+
GC.verify_compaction_references(double_heap: true, toward: :empty)
|
26
|
+
rescue NotImplementedError
|
27
|
+
# Some platforms don't support compaction
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
if GC.respond_to?(:auto_compact=)
|
32
|
+
GC.auto_compact = true
|
20
33
|
end
|
21
34
|
|
35
|
+
IS_JRUBY = RUBY_ENGINE == 'jruby'
|
36
|
+
|
37
|
+
IS_TRUFFLERUBY = RUBY_ENGINE == 'truffleruby'
|
38
|
+
|
22
39
|
# checking if Hash#[]= (rb_hash_aset) dedupes string keys
|
23
40
|
def automatic_string_keys_deduplication?
|
24
41
|
h = {}
|
@@ -36,7 +53,7 @@ def string_deduplication?
|
|
36
53
|
(-r1).equal?(-r2)
|
37
54
|
end
|
38
55
|
|
39
|
-
if
|
56
|
+
if IS_JRUBY
|
40
57
|
RSpec.configure do |c|
|
41
58
|
c.treat_symbols_as_metadata_keys_with_true_values = true
|
42
59
|
c.filter_run_excluding :encodings => !(defined? Encoding)
|
data/spec/timestamp_spec.rb
CHANGED
@@ -60,6 +60,44 @@ describe MessagePack::Timestamp do
|
|
60
60
|
it 'runs correctly (regression)' do
|
61
61
|
expect(factory.unpack(factory.pack(Time.utc(2200)))).to eq(Time.utc(2200))
|
62
62
|
end
|
63
|
+
|
64
|
+
let(:time32_max) { Time.new(2106, 2, 7, 6, 28, 15, "+00:00") }
|
65
|
+
it 'is serialized into timestamp32' do
|
66
|
+
expect(factory.pack(time32_max).size).to be 6
|
67
|
+
expect(factory.unpack(factory.pack(time32_max)).utc).to eq(time32_max)
|
68
|
+
end
|
69
|
+
|
70
|
+
let(:time64_min) { Time.new(2106, 2, 7, 6, 28, 16, "+00:00") }
|
71
|
+
it 'is serialized into timestamp64' do
|
72
|
+
expect(factory.pack(time64_min).size).to be 10
|
73
|
+
expect(factory.unpack(factory.pack(time64_min)).utc).to eq(time64_min)
|
74
|
+
end
|
75
|
+
|
76
|
+
let(:time64_max) { Time.at(Time.new(2514, 5, 30, 1, 53, 3, "+00:00").to_i, 999999999 / 1000.0r).utc } # TODO: use Time.at(sec, nsec, :nsec) when removing Ruby 2.4 from the list
|
77
|
+
it 'is serialized into timestamp64' do
|
78
|
+
expect(factory.pack(time64_max).size).to be 10
|
79
|
+
expect(factory.unpack(factory.pack(time64_max)).utc).to eq(time64_max)
|
80
|
+
end
|
81
|
+
|
82
|
+
let(:time96_positive_min) { Time.new(2514, 5, 30, 1, 53, 4, "+00:00") }
|
83
|
+
it 'is serialized into timestamp96' do
|
84
|
+
expect(factory.pack(time96_positive_min).size).to be 15
|
85
|
+
expect(factory.unpack(factory.pack(time96_positive_min)).utc).to eq(time96_positive_min)
|
86
|
+
end
|
87
|
+
|
88
|
+
let(:time96_min) { Time.at(-2**63).utc }
|
89
|
+
it 'is serialized into timestamp96' do
|
90
|
+
skip if IS_JRUBY || IS_TRUFFLERUBY # JRuby and TruffleRuby both use underlying Java time classes that do not support |year| >= 1 billion
|
91
|
+
expect(factory.pack(time96_min).size).to be 15
|
92
|
+
expect(factory.unpack(factory.pack(time96_min)).utc).to eq(time96_min)
|
93
|
+
end
|
94
|
+
|
95
|
+
let(:time96_max) { Time.at(2**63 - 1).utc }
|
96
|
+
it 'is serialized into timestamp96' do
|
97
|
+
skip if IS_JRUBY || IS_TRUFFLERUBY # JRuby and TruffleRuby both use underlying Java time classes that do not support |year| >= 1 billion
|
98
|
+
expect(factory.pack(time96_max).size).to be 15
|
99
|
+
expect(factory.unpack(factory.pack(time96_max)).utc).to eq(time96_max)
|
100
|
+
end
|
63
101
|
end
|
64
102
|
|
65
103
|
describe 'register_type with MessagePack::Timestamp' do
|
data/spec/unpacker_spec.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
# encoding: ascii-8bit
|
2
|
-
|
3
1
|
require 'stringio'
|
4
2
|
require 'tempfile'
|
5
3
|
require 'zlib'
|
@@ -36,6 +34,15 @@ describe MessagePack::Unpacker do
|
|
36
34
|
unpacker.each { |obj| hashes = obj }
|
37
35
|
expect(hashes[0].keys.first).to equal(hashes[1].keys.first)
|
38
36
|
end
|
37
|
+
|
38
|
+
it 'ensure strings are not deduplicated' do
|
39
|
+
sample_data = ["foo"]
|
40
|
+
sample_packed = MessagePack.pack(sample_data).force_encoding('ASCII-8BIT')
|
41
|
+
unpacker.feed(sample_packed)
|
42
|
+
ary = nil
|
43
|
+
unpacker.each { |obj| ary = obj }
|
44
|
+
expect(ary.first.frozen?).to eq(false)
|
45
|
+
end
|
39
46
|
end
|
40
47
|
|
41
48
|
it 'gets IO or object which has #read to read data from it' do
|
@@ -293,6 +300,21 @@ describe MessagePack::Unpacker do
|
|
293
300
|
MessagePack.unpack(MessagePack.pack(symbolized_hash), :symbolize_keys => true).should == symbolized_hash
|
294
301
|
end
|
295
302
|
|
303
|
+
it 'MessagePack.unpack symbolize_keys preserve encoding' do
|
304
|
+
hash = { :ascii => 1, :utf8_é => 2}
|
305
|
+
loaded_hash = MessagePack.load(MessagePack.pack(hash), :symbolize_keys => true)
|
306
|
+
|
307
|
+
hash.keys[0].encoding.should == Encoding::US_ASCII # Ruby coerce symbols to US-ASCII when possible.
|
308
|
+
loaded_hash.keys[0].should == hash.keys[0]
|
309
|
+
loaded_hash.keys[0].encoding.should == hash.keys[0].encoding
|
310
|
+
|
311
|
+
hash.keys[1].encoding.should == Encoding::UTF_8
|
312
|
+
loaded_hash.keys[1].should == hash.keys[1]
|
313
|
+
loaded_hash.keys[1].encoding.should == hash.keys[1].encoding
|
314
|
+
|
315
|
+
MessagePack.unpack(MessagePack.pack(hash), :symbolize_keys => true).should == hash
|
316
|
+
end
|
317
|
+
|
296
318
|
it 'Unpacker#unpack symbolize_keys' do
|
297
319
|
unpacker = MessagePack::Unpacker.new(:symbolize_keys => true)
|
298
320
|
symbolized_hash = {:a => 'b', :c => 'd'}
|
@@ -635,13 +657,23 @@ describe MessagePack::Unpacker do
|
|
635
657
|
MessagePack.unpack(MessagePack.pack(array)).size.should == 10_000
|
636
658
|
end
|
637
659
|
|
638
|
-
it '
|
660
|
+
it 'preserves string encoding (issue #200)' do
|
639
661
|
string = 'a'.force_encoding(Encoding::UTF_8)
|
640
662
|
MessagePack.unpack(MessagePack.pack(string)).encoding.should == string.encoding
|
641
663
|
|
642
664
|
string *= 256
|
643
665
|
MessagePack.unpack(MessagePack.pack(string)).encoding.should == string.encoding
|
644
666
|
end
|
667
|
+
|
668
|
+
it 'returns correct size for array16 (issue #127)' do
|
669
|
+
unpacker.feed("\xdc\x00\x01\x01")
|
670
|
+
unpacker.read_array_header.should == 1
|
671
|
+
end
|
672
|
+
|
673
|
+
it 'returns correct size for map16 (issue #127)' do
|
674
|
+
unpacker.feed("\xde\x00\x02\x01\x02\x03\x04")
|
675
|
+
unpacker.read_map_header.should == 2
|
676
|
+
end
|
645
677
|
end
|
646
678
|
|
647
679
|
context 'extensions' do
|
@@ -685,6 +717,18 @@ describe MessagePack::Unpacker do
|
|
685
717
|
described_class.new(:freeze => true)
|
686
718
|
end
|
687
719
|
|
720
|
+
if (-"test").equal?(-"test") # RUBY_VERSION >= "2.5"
|
721
|
+
it 'dedups strings' do
|
722
|
+
interned_str = -"test"
|
723
|
+
roundtrip = MessagePack.unpack(MessagePack.pack(interned_str), freeze: true)
|
724
|
+
expect(roundtrip).to be interned_str
|
725
|
+
|
726
|
+
interned_str = -""
|
727
|
+
roundtrip = MessagePack.unpack(MessagePack.pack(interned_str), freeze: true)
|
728
|
+
expect(roundtrip).to be interned_str
|
729
|
+
end
|
730
|
+
end
|
731
|
+
|
688
732
|
it 'can freeze objects when using .unpack' do
|
689
733
|
parsed_struct = MessagePack.unpack(buffer, freeze: true)
|
690
734
|
parsed_struct.should == struct
|
@@ -756,7 +800,13 @@ describe MessagePack::Unpacker do
|
|
756
800
|
|
757
801
|
context 'binary encoding', :encodings do
|
758
802
|
let :buffer do
|
759
|
-
MessagePack.pack({
|
803
|
+
MessagePack.pack({
|
804
|
+
'hello'.b => 'world'.b,
|
805
|
+
'nested'.b => [
|
806
|
+
'object'.b,
|
807
|
+
{'structure'.b => true},
|
808
|
+
]
|
809
|
+
})
|
760
810
|
end
|
761
811
|
|
762
812
|
let :unpacker do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: msgpack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sadayuki Furuhashi
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2022-09-30 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: bundler
|
@@ -46,14 +46,14 @@ dependencies:
|
|
46
46
|
requirements:
|
47
47
|
- - ">="
|
48
48
|
- !ruby/object:Gem::Version
|
49
|
-
version:
|
49
|
+
version: 1.1.9
|
50
50
|
type: :development
|
51
51
|
prerelease: false
|
52
52
|
version_requirements: !ruby/object:Gem::Requirement
|
53
53
|
requirements:
|
54
54
|
- - ">="
|
55
55
|
- !ruby/object:Gem::Version
|
56
|
-
version:
|
56
|
+
version: 1.1.9
|
57
57
|
- !ruby/object:Gem::Dependency
|
58
58
|
name: rspec
|
59
59
|
requirement: !ruby/object:Gem::Requirement
|
@@ -96,6 +96,20 @@ dependencies:
|
|
96
96
|
- - ">="
|
97
97
|
- !ruby/object:Gem::Version
|
98
98
|
version: '0'
|
99
|
+
- !ruby/object:Gem::Dependency
|
100
|
+
name: benchmark-ips
|
101
|
+
requirement: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - "~>"
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: 2.10.0
|
106
|
+
type: :development
|
107
|
+
prerelease: false
|
108
|
+
version_requirements: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - "~>"
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: 2.10.0
|
99
113
|
description: MessagePack is a binary-based efficient object serialization library.
|
100
114
|
It enables to exchange structured objects between many languages like JSON. But
|
101
115
|
unlike JSON, it is very fast and small.
|
@@ -108,25 +122,17 @@ extensions:
|
|
108
122
|
- ext/msgpack/extconf.rb
|
109
123
|
extra_rdoc_files: []
|
110
124
|
files:
|
125
|
+
- ".github/workflows/ci.yaml"
|
111
126
|
- ".gitignore"
|
112
127
|
- ".rubocop.yml"
|
113
|
-
- ".travis.yml"
|
114
128
|
- ChangeLog
|
115
129
|
- Gemfile
|
116
130
|
- LICENSE
|
117
131
|
- README.md
|
118
132
|
- Rakefile
|
119
133
|
- appveyor.yml
|
120
|
-
- bench/
|
121
|
-
-
|
122
|
-
- bench/pack_log_long.rb
|
123
|
-
- bench/pack_symbols.rb
|
124
|
-
- bench/run.sh
|
125
|
-
- bench/run_long.sh
|
126
|
-
- bench/run_symbols.sh
|
127
|
-
- bench/unpack.rb
|
128
|
-
- bench/unpack_log.rb
|
129
|
-
- bench/unpack_log_long.rb
|
134
|
+
- bench/bench.rb
|
135
|
+
- bin/console
|
130
136
|
- doclib/msgpack.rb
|
131
137
|
- doclib/msgpack/buffer.rb
|
132
138
|
- doclib/msgpack/core_ext.rb
|
@@ -176,6 +182,7 @@ files:
|
|
176
182
|
- ext/msgpack/unpacker_ext_registry.c
|
177
183
|
- ext/msgpack/unpacker_ext_registry.h
|
178
184
|
- lib/msgpack.rb
|
185
|
+
- lib/msgpack/bigint.rb
|
179
186
|
- lib/msgpack/core_ext.rb
|
180
187
|
- lib/msgpack/factory.rb
|
181
188
|
- lib/msgpack/packer.rb
|
@@ -186,6 +193,7 @@ files:
|
|
186
193
|
- lib/msgpack/version.rb
|
187
194
|
- msgpack.gemspec
|
188
195
|
- msgpack.org.md
|
196
|
+
- spec/bigint_spec.rb
|
189
197
|
- spec/cases.json
|
190
198
|
- spec/cases.msg
|
191
199
|
- spec/cases_compact.msg
|
@@ -229,32 +237,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
229
237
|
- !ruby/object:Gem::Version
|
230
238
|
version: '0'
|
231
239
|
requirements: []
|
232
|
-
rubygems_version: 3.2
|
240
|
+
rubygems_version: 3.1.2
|
233
241
|
signing_key:
|
234
242
|
specification_version: 4
|
235
243
|
summary: MessagePack, a binary-based efficient data interchange format.
|
236
|
-
test_files:
|
237
|
-
- spec/cases.json
|
238
|
-
- spec/cases.msg
|
239
|
-
- spec/cases_compact.msg
|
240
|
-
- spec/cases_spec.rb
|
241
|
-
- spec/cruby/buffer_io_spec.rb
|
242
|
-
- spec/cruby/buffer_packer.rb
|
243
|
-
- spec/cruby/buffer_spec.rb
|
244
|
-
- spec/cruby/buffer_unpacker.rb
|
245
|
-
- spec/cruby/unpacker_spec.rb
|
246
|
-
- spec/ext_value_spec.rb
|
247
|
-
- spec/exttypes.rb
|
248
|
-
- spec/factory_spec.rb
|
249
|
-
- spec/format_spec.rb
|
250
|
-
- spec/jruby/benchmarks/shootout_bm.rb
|
251
|
-
- spec/jruby/benchmarks/symbolize_keys_bm.rb
|
252
|
-
- spec/jruby/unpacker_spec.rb
|
253
|
-
- spec/msgpack_spec.rb
|
254
|
-
- spec/pack_spec.rb
|
255
|
-
- spec/packer_spec.rb
|
256
|
-
- spec/random_compat.rb
|
257
|
-
- spec/spec_helper.rb
|
258
|
-
- spec/timestamp_spec.rb
|
259
|
-
- spec/unpack_spec.rb
|
260
|
-
- spec/unpacker_spec.rb
|
244
|
+
test_files: []
|
data/.travis.yml
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
language: ruby
|
2
|
-
|
3
|
-
branches:
|
4
|
-
only:
|
5
|
-
- master
|
6
|
-
|
7
|
-
gemfile:
|
8
|
-
- Gemfile
|
9
|
-
|
10
|
-
before_install:
|
11
|
-
# This is only for Ruby 2.5.0, Bundler 1.16.1 and rubygems 2.7.3
|
12
|
-
# See https://github.com/travis-ci/travis-ci/issues/8969
|
13
|
-
- "[ \"x2.7.3\" = \"x\"$(gem --version) ] && gem update --system --no-document || echo \"no need to update rubygem\""
|
14
|
-
|
15
|
-
# http://rubies.travis-ci.org/
|
16
|
-
matrix:
|
17
|
-
include:
|
18
|
-
- rvm: 2.4.5
|
19
|
-
os: linux
|
20
|
-
- rvm: 2.5.8
|
21
|
-
os: linux
|
22
|
-
- rvm: 2.6.6
|
23
|
-
os: linux
|
24
|
-
- rvm: 2.6.6
|
25
|
-
os: osx
|
26
|
-
- rvm: 2.7.1
|
27
|
-
os: linux
|
28
|
-
- rvm: ruby-head
|
29
|
-
os: linux
|
30
|
-
- rvm: jruby-head
|
31
|
-
os: linux
|
32
|
-
- rvm: jruby-19mode
|
33
|
-
os: linux
|
34
|
-
allow_failures:
|
35
|
-
- rvm: 2.6.1
|
36
|
-
os: osx
|
37
|
-
- rvm: ruby-head
|
38
|
-
- rvm: jruby-head
|
39
|
-
- rvm: jruby-19mode
|
data/bench/pack.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
require 'viiite'
|
2
|
-
require 'msgpack'
|
3
|
-
|
4
|
-
data = { 'hello' => 'world', 'nested' => ['structure', {value: 42}] }
|
5
|
-
data_sym = { hello: 'world', nested: ['structure', {value: 42}] }
|
6
|
-
|
7
|
-
data = MessagePack.pack(:hello => 'world', :nested => ['structure', {:value => 42}])
|
8
|
-
|
9
|
-
Viiite.bench do |b|
|
10
|
-
b.range_over([10_000, 100_000, 1000_000], :runs) do |runs|
|
11
|
-
b.report(:strings) do
|
12
|
-
runs.times do
|
13
|
-
MessagePack.pack(data)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
b.report(:symbols) do
|
18
|
-
runs.times do
|
19
|
-
MessagePack.pack(data_sym)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
data/bench/pack_log.rb
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
require 'viiite'
|
2
|
-
require 'msgpack'
|
3
|
-
|
4
|
-
data_plain = { 'message' => '127.0.0.1 - - [10/Oct/2000:13:55:36 -0700] "GET /apache_pb.gif HTTP/1.0" 200 2326 "http://www.example.com/start.html" "Mozilla/4.08 [en] (Win98; I ;Nav)"' }
|
5
|
-
data_structure = {
|
6
|
-
'remote_host' => '127.0.0.1',
|
7
|
-
'remote_user' => '-',
|
8
|
-
'date' => '10/Oct/2000:13:55:36 -0700',
|
9
|
-
'request' => 'GET /apache_pb.gif HTTP/1.0',
|
10
|
-
'method' => 'GET',
|
11
|
-
'path' => '/apache_pb.gif',
|
12
|
-
'protocol' => 'HTTP/1.0',
|
13
|
-
'status' => 200,
|
14
|
-
'bytes' => 2326,
|
15
|
-
'referer' => 'http://www.example.com/start.html',
|
16
|
-
'agent' => 'Mozilla/4.08 [en] (Win98; I ;Nav)',
|
17
|
-
}
|
18
|
-
|
19
|
-
Viiite.bench do |b|
|
20
|
-
b.range_over([10_000, 100_000, 1000_000], :runs) do |runs|
|
21
|
-
b.report(:plain) do
|
22
|
-
runs.times do
|
23
|
-
MessagePack.pack(data_plain)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
b.report(:structure) do
|
28
|
-
runs.times do
|
29
|
-
MessagePack.pack(data_structure)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
data/bench/pack_log_long.rb
DELETED
@@ -1,65 +0,0 @@
|
|
1
|
-
# viiite report --regroup bench,threads bench/pack_log_long.rb
|
2
|
-
|
3
|
-
require 'viiite'
|
4
|
-
require 'msgpack'
|
5
|
-
|
6
|
-
data_plain = { 'message' => '127.0.0.1 - - [10/Oct/2000:13:55:36 -0700] "GET /apache_pb.gif HTTP/1.0" 200 2326 "http://www.example.com/start.html" "Mozilla/4.08 [en] (Win98; I ;Nav)"' }
|
7
|
-
data_structure = {
|
8
|
-
'remote_host' => '127.0.0.1',
|
9
|
-
'remote_user' => '-',
|
10
|
-
'date' => '10/Oct/2000:13:55:36 -0700',
|
11
|
-
'request' => 'GET /apache_pb.gif HTTP/1.0',
|
12
|
-
'method' => 'GET',
|
13
|
-
'path' => '/apache_pb.gif',
|
14
|
-
'protocol' => 'HTTP/1.0',
|
15
|
-
'status' => 200,
|
16
|
-
'bytes' => 2326,
|
17
|
-
'referer' => 'http://www.example.com/start.html',
|
18
|
-
'agent' => 'Mozilla/4.08 [en] (Win98; I ;Nav)',
|
19
|
-
}
|
20
|
-
|
21
|
-
seconds = 3600 # 1 hour
|
22
|
-
|
23
|
-
Viiite.bench do |b|
|
24
|
-
b.range_over([1, 2, 4, 8, 16], :threads) do |threads|
|
25
|
-
b.report(:plain) do
|
26
|
-
ths = []
|
27
|
-
end_at = Time.now + seconds
|
28
|
-
threads.times do
|
29
|
-
t = Thread.new do
|
30
|
-
packs = 0
|
31
|
-
while Time.now < end_at
|
32
|
-
10000.times do
|
33
|
-
MessagePack.pack(data_plain)
|
34
|
-
end
|
35
|
-
packs += 10000
|
36
|
-
end
|
37
|
-
packs
|
38
|
-
end
|
39
|
-
ths.push t
|
40
|
-
end
|
41
|
-
sum = ths.reduce(0){|r,t| r + t.value }
|
42
|
-
puts "MessagePack.pack, plain, #{threads} threads: #{sum} times, #{sum / seconds} times/second."
|
43
|
-
end
|
44
|
-
|
45
|
-
b.report(:structure) do
|
46
|
-
ths = []
|
47
|
-
end_at = Time.now + seconds
|
48
|
-
threads.times do
|
49
|
-
t = Thread.new do
|
50
|
-
packs = 0
|
51
|
-
while Time.now < end_at
|
52
|
-
10000.times do
|
53
|
-
MessagePack.pack(data_structure)
|
54
|
-
end
|
55
|
-
packs += 10000
|
56
|
-
end
|
57
|
-
packs
|
58
|
-
end
|
59
|
-
ths.push t
|
60
|
-
end
|
61
|
-
sum = ths.reduce(0){|r,t| r + t.value }
|
62
|
-
puts "MessagePack.pack, structured, #{threads} threads: #{sum} times, #{sum / seconds} times/second."
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
data/bench/pack_symbols.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
require 'viiite'
|
2
|
-
require 'msgpack'
|
3
|
-
|
4
|
-
data = :symbol
|
5
|
-
|
6
|
-
Viiite.bench do |b|
|
7
|
-
b.variation_point :branch, `git rev-parse --abbrev-ref HEAD`
|
8
|
-
|
9
|
-
b.range_over([:symbol, :none], :reg_type) do |reg_type|
|
10
|
-
packer = MessagePack::Packer.new
|
11
|
-
packer.register_type(0x00, Symbol, :to_msgpack_ext) if reg_type == :symbol
|
12
|
-
|
13
|
-
b.range_over([100_000, 1_000_000, 10_000_000], :count) do |count|
|
14
|
-
packer.clear
|
15
|
-
b.report(:multi_run) do
|
16
|
-
count.times do
|
17
|
-
packer.pack(data)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
packer.clear
|
22
|
-
items_data = [].fill(data, 0, count)
|
23
|
-
b.report(:large_run) do
|
24
|
-
packer.pack(items_data)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
data/bench/run.sh
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
#!/bin/sh
|
2
|
-
|
3
|
-
# prerequisites
|
4
|
-
# $ rbenv shell 2.2.1 (or jruby-x.x.x or ...)
|
5
|
-
# $ rake install
|
6
|
-
|
7
|
-
echo "pack"
|
8
|
-
viiite report --regroup bench,runs bench/pack.rb
|
9
|
-
echo "unpack"
|
10
|
-
viiite report --regroup bench,runs bench/unpack.rb
|
11
|
-
echo "pack log"
|
12
|
-
viiite report --regroup bench,runs bench/pack_log.rb
|
13
|
-
echo "unpack log"
|
14
|
-
viiite report --regroup bench,runs bench/unpack_log.rb
|
data/bench/run_long.sh
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
#!/bin/sh
|
2
|
-
|
3
|
-
# prerequisites
|
4
|
-
# $ sudo apt-get install sysstat
|
5
|
-
# $ rbenv shell 2.2.1 (or jruby-x.x.x or ...)
|
6
|
-
# $ rake install
|
7
|
-
|
8
|
-
# 60 * 600 : 60*60 * 5[threads] * 2[bench]
|
9
|
-
|
10
|
-
ruby -v
|
11
|
-
|
12
|
-
echo "pack log long"
|
13
|
-
viiite report --regroup bench,threads bench/pack_log_long.rb &
|
14
|
-
sar -o pack_log_long.sar -r 60 600 > /dev/null 2>&1 &
|
15
|
-
|
16
|
-
declare -i i=0
|
17
|
-
while [ $i -lt 600 ]; do
|
18
|
-
ps auxww | grep ruby | grep -v grep | awk '{print $5,$6;}' >> pack_log_long.mem.txt
|
19
|
-
i=i+1
|
20
|
-
sleep 60
|
21
|
-
done
|
22
|
-
|
23
|
-
sleep 120 # cool down
|
24
|
-
|
25
|
-
echo "unpack log long"
|
26
|
-
viiite report --regroup bench,threads bench/unpack_log_long.rb &
|
27
|
-
sar -o unpack_log_long.sar -r 60 600 > /dev/null 2>&1 &
|
28
|
-
|
29
|
-
i=0
|
30
|
-
while [ $i -lt 600 ]; do
|
31
|
-
ps auxww | grep ruby | grep -v grep | awk '{print $5,$6;}' >> pack_log_long.mem.txt
|
32
|
-
i=i+1
|
33
|
-
sleep 60
|
34
|
-
done
|
35
|
-
|
data/bench/run_symbols.sh
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
#!/bin/sh
|
2
|
-
|
3
|
-
# so master and this branch have the benchmark file in any case
|
4
|
-
cp bench/pack_symbols.rb bench/pack_symbols_tmp.rb
|
5
|
-
|
6
|
-
benchmark=""
|
7
|
-
current_branch=`git rev-parse --abbrev-ref HEAD`
|
8
|
-
|
9
|
-
for branch in master $current_branch; do
|
10
|
-
echo "Testing branch $branch"
|
11
|
-
git checkout $branch
|
12
|
-
|
13
|
-
echo "Installing gem..."
|
14
|
-
rake install
|
15
|
-
|
16
|
-
echo "Running benchmark..."
|
17
|
-
if [ "$benchmark" ]; then
|
18
|
-
benchmark+=$'\n'
|
19
|
-
fi
|
20
|
-
benchmark+=$(viiite run bench/pack_symbols_tmp.rb)
|
21
|
-
echo
|
22
|
-
done
|
23
|
-
|
24
|
-
rm bench/pack_symbols_tmp.rb
|
25
|
-
|
26
|
-
echo "$benchmark" | viiite report --regroup bench,reg_type,count,branch
|
data/bench/unpack.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
require 'viiite'
|
2
|
-
require 'msgpack'
|
3
|
-
|
4
|
-
data = MessagePack.pack(:hello => 'world', :nested => ['structure', {:value => 42}])
|
5
|
-
|
6
|
-
Viiite.bench do |b|
|
7
|
-
b.range_over([10_000, 100_000, 1000_000], :runs) do |runs|
|
8
|
-
b.report(:strings) do
|
9
|
-
runs.times do
|
10
|
-
MessagePack.unpack(data)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
b.report(:symbols) do
|
15
|
-
options = {:symbolize_keys => true}
|
16
|
-
runs.times do
|
17
|
-
MessagePack.unpack(data, options)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
data/bench/unpack_log.rb
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
require 'viiite'
|
2
|
-
require 'msgpack'
|
3
|
-
|
4
|
-
data_plain = MessagePack.pack({ 'message' => '127.0.0.1 - - [10/Oct/2000:13:55:36 -0700] "GET /apache_pb.gif HTTP/1.0" 200 2326 "http://www.example.com/start.html" "Mozilla/4.08 [en] (Win98; I ;Nav)"' })
|
5
|
-
|
6
|
-
data_structure = MessagePack.pack({
|
7
|
-
'remote_host' => '127.0.0.1',
|
8
|
-
'remote_user' => '-',
|
9
|
-
'date' => '10/Oct/2000:13:55:36 -0700',
|
10
|
-
'request' => 'GET /apache_pb.gif HTTP/1.0',
|
11
|
-
'method' => 'GET',
|
12
|
-
'path' => '/apache_pb.gif',
|
13
|
-
'protocol' => 'HTTP/1.0',
|
14
|
-
'status' => 200,
|
15
|
-
'bytes' => 2326,
|
16
|
-
'referer' => 'http://www.example.com/start.html',
|
17
|
-
'agent' => 'Mozilla/4.08 [en] (Win98; I ;Nav)',
|
18
|
-
})
|
19
|
-
|
20
|
-
Viiite.bench do |b|
|
21
|
-
b.range_over([10_000, 100_000, 1000_000], :runs) do |runs|
|
22
|
-
b.report(:plain) do
|
23
|
-
runs.times do
|
24
|
-
MessagePack.unpack(data_plain)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
b.report(:structure) do
|
29
|
-
runs.times do
|
30
|
-
MessagePack.unpack(data_structure)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|