pump 0.11.0 → 0.12.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 +5 -5
- data/.gitignore +1 -0
- data/benchmarks/Gemfile +5 -0
- data/benchmarks/encode.rb +144 -6
- data/lib/pump/json.rb +1 -1
- data/lib/pump/version.rb +1 -1
- data/lib/pump/xml/tag.rb +3 -3
- data/lib/pump/xml.rb +1 -1
- data/spec/spec_helper.rb +2 -1
- metadata +3 -9
- data/.ruby-version +0 -1
- data/benchmarks/Gemfile.lock +0 -59
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: b313c4c52ba0c1c54a0de5fd236acc82c0433b7b959fb836a640dd0933ad69f0
|
|
4
|
+
data.tar.gz: 99c203f2745a810a46e0dc9bdc21bf8c0dab5e68acf4559c00bdf4386118618b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5453a1bb33f44c4800cccb74eb52fccaa3ad1f3429e08d63c875374cb159a13c8715e38e02c6945cd6297c03c6ba821a9a7bca7d0e72f7e0c107c1dbe65e3163
|
|
7
|
+
data.tar.gz: b538758fbbfbbe2160273c05edd5a6b0bd1f373984e43261e4519ab37fa46b33027307db48aa799088e933172d7d431d3c55a79ba09a2834bbdf9c7085471d2c
|
data/.gitignore
CHANGED
data/benchmarks/Gemfile
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
source 'https://rubygems.org'
|
|
2
2
|
|
|
3
|
+
gem 'benchmark-memory'
|
|
4
|
+
|
|
3
5
|
gem 'pump', path: '..'
|
|
4
6
|
gem 'ox'
|
|
5
7
|
gem 'oj'
|
|
6
8
|
gem 'yajl-ruby'
|
|
7
9
|
gem 'activemodel'
|
|
8
10
|
gem 'activemodel-serializers-xml'
|
|
11
|
+
gem 'fast_jsonapi'
|
|
9
12
|
gem 'to_json', github: 'ahacking/to_json'
|
|
13
|
+
gem 'panko_serializer'
|
|
14
|
+
gem 'activerecord'
|
data/benchmarks/encode.rb
CHANGED
|
@@ -1,15 +1,23 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
# frozen_string_literal: true
|
|
4
|
+
|
|
2
5
|
require 'rubygems'
|
|
3
6
|
require 'bundler/setup'
|
|
4
7
|
|
|
5
8
|
require 'benchmark'
|
|
9
|
+
require 'benchmark-memory'
|
|
10
|
+
|
|
6
11
|
require 'to_json'
|
|
7
12
|
require 'pump'
|
|
8
13
|
require 'ox'
|
|
9
14
|
require 'oj'
|
|
10
15
|
require 'yajl'
|
|
16
|
+
require 'active_record'
|
|
11
17
|
require 'active_model'
|
|
12
18
|
require 'activemodel-serializers-xml'
|
|
19
|
+
require 'fast_jsonapi'
|
|
20
|
+
require 'panko_serializer'
|
|
13
21
|
|
|
14
22
|
class Person < Struct.new(:name, :age, :created_at)
|
|
15
23
|
include ActiveModel::Serializers::Xml if defined?(ActiveModel)
|
|
@@ -18,6 +26,10 @@ class Person < Struct.new(:name, :age, :created_at)
|
|
|
18
26
|
def attributes
|
|
19
27
|
{'name' => name, 'age' => age, 'created_at' => created_at}
|
|
20
28
|
end
|
|
29
|
+
|
|
30
|
+
def attributes_symbols
|
|
31
|
+
{:name => name, :age => age, :created_at => created_at}
|
|
32
|
+
end
|
|
21
33
|
end
|
|
22
34
|
|
|
23
35
|
pump_json = Pump::Json.new('person', [
|
|
@@ -26,6 +38,12 @@ pump_json = Pump::Json.new('person', [
|
|
|
26
38
|
{:name => :name}
|
|
27
39
|
])
|
|
28
40
|
|
|
41
|
+
module PankoBench
|
|
42
|
+
class PeopleSerializer < Panko::Serializer
|
|
43
|
+
attributes :name, :age, :created_at
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
29
47
|
module ToJsonBench
|
|
30
48
|
|
|
31
49
|
class PeopleSerializer
|
|
@@ -49,6 +67,13 @@ module ToJsonBench
|
|
|
49
67
|
end
|
|
50
68
|
end
|
|
51
69
|
|
|
70
|
+
class FastJsonapiSerializer
|
|
71
|
+
include FastJsonapi::ObjectSerializer
|
|
72
|
+
set_type :person # optional
|
|
73
|
+
set_id :name # optional
|
|
74
|
+
attributes :age, :created_at
|
|
75
|
+
end
|
|
76
|
+
|
|
52
77
|
# Not optimized pump
|
|
53
78
|
pump = Pump::Xml.new('person', [
|
|
54
79
|
{:age => :age, :attributes => {:type => 'integer'}},
|
|
@@ -110,32 +135,43 @@ times = ARGV[1] ? ARGV[1].to_i : 1000
|
|
|
110
135
|
puts "Starting benchmark serializing array with #{array.size} entries #{times} times\n\n"
|
|
111
136
|
|
|
112
137
|
Benchmark.bmbm { |x|
|
|
113
|
-
|
|
114
138
|
x.report("Pump::Json#encode") {
|
|
115
139
|
times.times {
|
|
116
140
|
pump_json.encode(array)
|
|
117
141
|
}
|
|
118
142
|
}
|
|
119
143
|
|
|
144
|
+
x.report("Panko") {
|
|
145
|
+
times.times {
|
|
146
|
+
Panko::ArraySerializer.new(array, each_serializer: PankoBench::PeopleSerializer).to_json
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
120
150
|
x.report("ToJson") {
|
|
121
151
|
times.times {
|
|
122
152
|
ToJsonBench::PeopleSerializer.json!(array)
|
|
123
153
|
}
|
|
124
154
|
}
|
|
125
155
|
|
|
156
|
+
x.report("fast_jsonapi") {
|
|
157
|
+
times.times {
|
|
158
|
+
FastJsonapiSerializer.new(array).serialized_json
|
|
159
|
+
}
|
|
160
|
+
} if false
|
|
161
|
+
|
|
126
162
|
x.report("Pump::Xml#encode") {
|
|
127
163
|
times.times {
|
|
128
164
|
pump.encode(array)
|
|
129
165
|
}
|
|
130
|
-
}
|
|
166
|
+
} if false
|
|
131
167
|
|
|
132
168
|
x.report("Pump::Xml#encode (optimized)") {
|
|
133
169
|
times.times {
|
|
134
170
|
pump_optimized.encode(array)
|
|
135
171
|
}
|
|
136
|
-
}
|
|
172
|
+
} if false
|
|
137
173
|
|
|
138
|
-
if defined?(Ox)
|
|
174
|
+
if defined?(Ox) && false
|
|
139
175
|
x.report("Ox") {
|
|
140
176
|
times.times {
|
|
141
177
|
serialize_with_ox(array)
|
|
@@ -144,11 +180,23 @@ Benchmark.bmbm { |x|
|
|
|
144
180
|
end
|
|
145
181
|
|
|
146
182
|
if defined?(Oj)
|
|
147
|
-
x.report("Oj") {
|
|
183
|
+
x.report("Oj compat") {
|
|
148
184
|
times.times {
|
|
149
185
|
Oj.dump(array.map(&:attributes), :mode => :compat)
|
|
150
186
|
}
|
|
151
187
|
}
|
|
188
|
+
|
|
189
|
+
x.report("Oj strict") {
|
|
190
|
+
times.times {
|
|
191
|
+
Oj.dump(array.map(&:attributes).map{|it| it['created_at'] = it['created_at'].to_i;it}, :mode => :strict)
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
x.report("Oj wab") {
|
|
196
|
+
times.times {
|
|
197
|
+
Oj.dump(array.map(&:attributes_symbols).map{|it| it[:created_at] = it[:created_at].to_i;it}, :mode => :wab)
|
|
198
|
+
}
|
|
199
|
+
}
|
|
152
200
|
end
|
|
153
201
|
|
|
154
202
|
if defined?(Yajl)
|
|
@@ -157,14 +205,104 @@ Benchmark.bmbm { |x|
|
|
|
157
205
|
Yajl::Encoder.encode(array.map(&:attributes))
|
|
158
206
|
}
|
|
159
207
|
}
|
|
160
|
-
end
|
|
208
|
+
end if false
|
|
161
209
|
|
|
162
210
|
if defined?(ActiveModel)
|
|
163
211
|
x.report("ActiveModel#to_xml") {
|
|
164
212
|
times.times {
|
|
165
213
|
array.to_xml
|
|
166
214
|
}
|
|
215
|
+
} if false
|
|
216
|
+
|
|
217
|
+
x.report("ActiveModel#to_json") {
|
|
218
|
+
times.times {
|
|
219
|
+
array.to_json
|
|
220
|
+
}
|
|
167
221
|
}
|
|
222
|
+
end
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
Benchmark.memory() { |x|
|
|
226
|
+
x.compare!
|
|
227
|
+
|
|
228
|
+
x.report("Pump::Json#encode") {
|
|
229
|
+
times.times {
|
|
230
|
+
pump_json.encode(array)
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
x.report("Panko") {
|
|
235
|
+
times.times {
|
|
236
|
+
Panko::ArraySerializer.new(array, each_serializer: PankoBench::PeopleSerializer).to_json
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
x.report("ToJson") {
|
|
241
|
+
times.times {
|
|
242
|
+
ToJsonBench::PeopleSerializer.json!(array)
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
x.report("fast_jsonapi") {
|
|
247
|
+
times.times {
|
|
248
|
+
FastJsonapiSerializer.new(array).serialized_json
|
|
249
|
+
}
|
|
250
|
+
} if false
|
|
251
|
+
|
|
252
|
+
x.report("Pump::Xml#encode") {
|
|
253
|
+
times.times {
|
|
254
|
+
pump.encode(array)
|
|
255
|
+
}
|
|
256
|
+
} if false
|
|
257
|
+
|
|
258
|
+
x.report("Pump::Xml#encode (optimized)") {
|
|
259
|
+
times.times {
|
|
260
|
+
pump_optimized.encode(array)
|
|
261
|
+
}
|
|
262
|
+
} if false
|
|
263
|
+
|
|
264
|
+
if defined?(Ox) && false
|
|
265
|
+
x.report("Ox") {
|
|
266
|
+
times.times {
|
|
267
|
+
serialize_with_ox(array)
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
end
|
|
271
|
+
|
|
272
|
+
if defined?(Oj)
|
|
273
|
+
x.report("Oj compat") {
|
|
274
|
+
times.times {
|
|
275
|
+
Oj.dump(array.map(&:attributes), :mode => :compat)
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
x.report("Oj strict") {
|
|
280
|
+
times.times {
|
|
281
|
+
Oj.dump(array.map(&:attributes).map{|it| it['created_at'] = it['created_at'].to_i;it}, :mode => :strict)
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
x.report("Oj wab") {
|
|
286
|
+
times.times {
|
|
287
|
+
Oj.dump(array.map(&:attributes_symbols).map{|it| it[:created_at] = it[:created_at].to_i;it}, :mode => :wab)
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
end
|
|
291
|
+
|
|
292
|
+
if defined?(Yajl)
|
|
293
|
+
x.report("Yajl") {
|
|
294
|
+
times.times {
|
|
295
|
+
Yajl::Encoder.encode(array.map(&:attributes))
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
end if false
|
|
299
|
+
|
|
300
|
+
if defined?(ActiveModel)
|
|
301
|
+
x.report("ActiveModel#to_xml") {
|
|
302
|
+
times.times {
|
|
303
|
+
array.to_xml
|
|
304
|
+
}
|
|
305
|
+
} if false
|
|
168
306
|
|
|
169
307
|
x.report("ActiveModel#to_json") {
|
|
170
308
|
times.times {
|
data/lib/pump/json.rb
CHANGED
data/lib/pump/version.rb
CHANGED
data/lib/pump/xml/tag.rb
CHANGED
|
@@ -41,7 +41,7 @@ module Pump
|
|
|
41
41
|
end
|
|
42
42
|
|
|
43
43
|
def value_and_close_tag(path=nil)
|
|
44
|
-
value = value_nodes? ? nodes.first.to_s(path) : ("\n" << nodes.map(&:to_s).join)
|
|
44
|
+
value = value_nodes? ? nodes.first.to_s(path) : (+"\n" << nodes.map(&:to_s).join)
|
|
45
45
|
">#{value}#{tabs unless value_nodes?}</#{format_name(name)}>\n"
|
|
46
46
|
end
|
|
47
47
|
|
|
@@ -56,7 +56,7 @@ module Pump
|
|
|
56
56
|
|
|
57
57
|
def attributes_string
|
|
58
58
|
return "" if !attributes || attributes.size == 0
|
|
59
|
-
attributes.inject(
|
|
59
|
+
attributes.inject(+"") do |str, (key, value)|
|
|
60
60
|
str << " #{key}=\\\"#{value}\\\""
|
|
61
61
|
end
|
|
62
62
|
end
|
|
@@ -92,4 +92,4 @@ module Pump
|
|
|
92
92
|
end
|
|
93
93
|
end
|
|
94
94
|
end
|
|
95
|
-
end
|
|
95
|
+
end
|
data/lib/pump/xml.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: pump
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.12.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Sebastian Munz
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 2026-02-13 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: activesupport
|
|
@@ -75,7 +74,6 @@ extra_rdoc_files: []
|
|
|
75
74
|
files:
|
|
76
75
|
- ".gitignore"
|
|
77
76
|
- ".rspec"
|
|
78
|
-
- ".ruby-version"
|
|
79
77
|
- ".travis.yml"
|
|
80
78
|
- ".yardopts"
|
|
81
79
|
- CHANGES.md
|
|
@@ -85,7 +83,6 @@ files:
|
|
|
85
83
|
- README.md
|
|
86
84
|
- Rakefile
|
|
87
85
|
- benchmarks/Gemfile
|
|
88
|
-
- benchmarks/Gemfile.lock
|
|
89
86
|
- benchmarks/encode.rb
|
|
90
87
|
- gemfiles/activesupport-4
|
|
91
88
|
- gemfiles/activesupport-5
|
|
@@ -118,7 +115,6 @@ homepage: https://github.com/yolk/pump
|
|
|
118
115
|
licenses:
|
|
119
116
|
- MIT
|
|
120
117
|
metadata: {}
|
|
121
|
-
post_install_message:
|
|
122
118
|
rdoc_options: []
|
|
123
119
|
require_paths:
|
|
124
120
|
- lib
|
|
@@ -133,9 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
133
129
|
- !ruby/object:Gem::Version
|
|
134
130
|
version: '0'
|
|
135
131
|
requirements: []
|
|
136
|
-
|
|
137
|
-
rubygems_version: 2.6.14
|
|
138
|
-
signing_key:
|
|
132
|
+
rubygems_version: 3.6.2
|
|
139
133
|
specification_version: 4
|
|
140
134
|
summary: Fast but inflexible XML and JSON encoding for ruby objects.
|
|
141
135
|
test_files:
|
data/.ruby-version
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
2.4.3
|
data/benchmarks/Gemfile.lock
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
GIT
|
|
2
|
-
remote: https://github.com/ahacking/to_json.git
|
|
3
|
-
revision: 6fe8a17f9652da0d29c2ef8637630f7c34977e00
|
|
4
|
-
specs:
|
|
5
|
-
to_json (0.0.4)
|
|
6
|
-
oj (>= 2.9.4)
|
|
7
|
-
|
|
8
|
-
PATH
|
|
9
|
-
remote: ..
|
|
10
|
-
specs:
|
|
11
|
-
pump (0.6.6)
|
|
12
|
-
activesupport (>= 4.0)
|
|
13
|
-
oj (>= 3.0)
|
|
14
|
-
|
|
15
|
-
GEM
|
|
16
|
-
remote: https://rubygems.org/
|
|
17
|
-
specs:
|
|
18
|
-
activemodel (5.1.2)
|
|
19
|
-
activesupport (= 5.1.2)
|
|
20
|
-
activemodel-serializers-xml (1.0.1)
|
|
21
|
-
activemodel (> 5.x)
|
|
22
|
-
activerecord (> 5.x)
|
|
23
|
-
activesupport (> 5.x)
|
|
24
|
-
builder (~> 3.1)
|
|
25
|
-
activerecord (5.1.2)
|
|
26
|
-
activemodel (= 5.1.2)
|
|
27
|
-
activesupport (= 5.1.2)
|
|
28
|
-
arel (~> 8.0)
|
|
29
|
-
activesupport (5.1.2)
|
|
30
|
-
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
31
|
-
i18n (~> 0.7)
|
|
32
|
-
minitest (~> 5.1)
|
|
33
|
-
tzinfo (~> 1.1)
|
|
34
|
-
arel (8.0.0)
|
|
35
|
-
builder (3.2.3)
|
|
36
|
-
concurrent-ruby (1.0.5)
|
|
37
|
-
i18n (0.8.4)
|
|
38
|
-
minitest (5.10.2)
|
|
39
|
-
oj (3.2.0)
|
|
40
|
-
ox (2.5.0)
|
|
41
|
-
thread_safe (0.3.6)
|
|
42
|
-
tzinfo (1.2.3)
|
|
43
|
-
thread_safe (~> 0.1)
|
|
44
|
-
yajl-ruby (1.3.0)
|
|
45
|
-
|
|
46
|
-
PLATFORMS
|
|
47
|
-
ruby
|
|
48
|
-
|
|
49
|
-
DEPENDENCIES
|
|
50
|
-
activemodel
|
|
51
|
-
activemodel-serializers-xml
|
|
52
|
-
oj
|
|
53
|
-
ox
|
|
54
|
-
pump!
|
|
55
|
-
to_json!
|
|
56
|
-
yajl-ruby
|
|
57
|
-
|
|
58
|
-
BUNDLED WITH
|
|
59
|
-
1.15.1
|