json_pure 1.8.6 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +0 -1
- data/.travis.yml +5 -3
- data/CHANGES +5 -5
- data/Gemfile +3 -1
- data/README.md +131 -84
- data/Rakefile +17 -10
- data/VERSION +1 -1
- data/ext/json/ext/generator/generator.c +1 -52
- data/ext/json/ext/generator/generator.h +0 -5
- data/ext/json/ext/parser/extconf.rb +3 -0
- data/ext/json/ext/parser/parser.c +304 -458
- data/ext/json/ext/parser/parser.h +0 -1
- data/ext/json/ext/parser/parser.rl +35 -152
- data/ext/json/extconf.rb +0 -1
- data/java/src/json/ext/Generator.java +2 -5
- data/java/src/json/ext/GeneratorState.java +2 -54
- data/java/src/json/ext/OptionsReader.java +1 -1
- data/java/src/json/ext/Parser.java +109 -409
- data/java/src/json/ext/Parser.rl +24 -117
- data/java/src/json/ext/RuntimeInfo.java +0 -4
- data/json.gemspec +0 -0
- data/json_pure.gemspec +7 -7
- data/lib/json.rb +1 -0
- data/lib/json/add/bigdecimal.rb +1 -0
- data/lib/json/add/complex.rb +2 -1
- data/lib/json/add/core.rb +1 -0
- data/lib/json/add/date.rb +1 -1
- data/lib/json/add/date_time.rb +1 -1
- data/lib/json/add/exception.rb +1 -1
- data/lib/json/add/ostruct.rb +1 -1
- data/lib/json/add/range.rb +1 -1
- data/lib/json/add/rational.rb +1 -0
- data/lib/json/add/regexp.rb +1 -1
- data/lib/json/add/struct.rb +1 -1
- data/lib/json/add/symbol.rb +1 -1
- data/lib/json/add/time.rb +1 -1
- data/lib/json/common.rb +24 -52
- data/lib/json/ext.rb +0 -6
- data/lib/json/generic_object.rb +5 -4
- data/lib/json/pure.rb +2 -8
- data/lib/json/pure/generator.rb +51 -123
- data/lib/json/pure/parser.rb +28 -80
- data/lib/json/version.rb +2 -1
- data/references/rfc7159.txt +899 -0
- data/tests/fixtures/obsolete_fail1.json +1 -0
- data/tests/{test_json_addition.rb → json_addition_test.rb} +22 -25
- data/tests/json_common_interface_test.rb +126 -0
- data/tests/json_encoding_test.rb +105 -0
- data/tests/json_ext_parser_test.rb +15 -0
- data/tests/{test_json_fixtures.rb → json_fixtures_test.rb} +5 -8
- data/tests/{test_json_generate.rb → json_generator_test.rb} +65 -37
- data/tests/{test_json_generic_object.rb → json_generic_object_test.rb} +15 -8
- data/tests/json_parser_test.rb +448 -0
- data/tests/json_string_matching_test.rb +38 -0
- data/tests/test_helper.rb +23 -0
- data/tools/fuzz.rb +1 -9
- metadata +18 -31
- data/TODO +0 -1
- data/tests/fixtures/fail1.json +0 -1
- data/tests/setup_variant.rb +0 -11
- data/tests/test_json.rb +0 -519
- data/tests/test_json_encoding.rb +0 -65
- data/tests/test_json_string_matching.rb +0 -39
- data/tests/test_json_unicode.rb +0 -72
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 86f8007c8df2b283f91d24c6ac50baa7506d07b3
|
4
|
+
data.tar.gz: d65cda4d6da0ca77045b04e5579075c7ee340b1b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f9c1d08d19c8396f3a0fd0665e74f06c883b11ead22819a4f89faf61e47ff044ecda86d4ee62e5735ff56fcd5aac1ecf39f3791c1efd18add044d36152c959fa
|
7
|
+
data.tar.gz: 630de42ed6583fa2b720d1423be0bea1a59fcdcd4a26498249759d24715da49e21b1256e6077a7b9e011ba162221e8a5a0e200b5afd6e517ef18bb2a0904be9d
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -4,15 +4,17 @@ language: ruby
|
|
4
4
|
|
5
5
|
# Specify which ruby versions you wish to run your tests on, each version will be used
|
6
6
|
rvm:
|
7
|
-
- 1.9.3
|
8
7
|
- 2.0.0
|
9
8
|
- 2.1
|
10
9
|
- 2.2
|
11
|
-
- 2.3.
|
12
|
-
-
|
10
|
+
- 2.3.1
|
11
|
+
- ruby-head
|
13
12
|
matrix:
|
14
13
|
include:
|
15
14
|
- rvm: jruby
|
16
15
|
env: JRUBY_OPTS="--2.0"
|
16
|
+
allow_failures:
|
17
|
+
- rvm: rbx-2
|
18
|
+
- rvm: ruby-head
|
17
19
|
script: "bundle exec rake"
|
18
20
|
sudo: false
|
data/CHANGES
CHANGED
@@ -1,7 +1,8 @@
|
|
1
|
-
|
2
|
-
*
|
3
|
-
|
4
|
-
*
|
1
|
+
2015-09-11 (2.0.0)
|
2
|
+
* Now complies to newest JSON RFC 7159.
|
3
|
+
* Implements compatibiliy to ruby 2.4 integer unification.
|
4
|
+
* Drops support for old rubies whose life has ended, that is rubies < 2.0.
|
5
|
+
Also see https://www.ruby-lang.org/en/news/2014/07/01/eol-for-1-8-7-and-1-9-2/
|
5
6
|
* There were still some mentions of dual GPL licensing in the source, but JSON
|
6
7
|
has just the Ruby license that itself includes an explicit dual-licensing
|
7
8
|
clause that allows covered software to be distributed under the terms of
|
@@ -9,7 +10,6 @@
|
|
9
10
|
however a GPL compatible license according to the Free Software Foundation.
|
10
11
|
I changed these mentions to be consistent with the Ruby license setting in
|
11
12
|
the gemspec files which were already correct now.
|
12
|
-
---------- (1.8.4) Skipped.
|
13
13
|
2015-06-01 (1.8.3)
|
14
14
|
* Fix potential memory leak, thx to nobu.
|
15
15
|
2015-01-08 (1.8.2)
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
# JSON implementation for Ruby
|
1
|
+
# JSON implementation for Ruby ![Travis Widget]
|
2
|
+
[Travis Widget]: http://travis-ci.org/flori/json.svg?branch=master
|
2
3
|
|
3
4
|
## Description
|
4
5
|
|
@@ -25,13 +26,6 @@ encoded, please use the to\_json\_raw\_object method of String (which produces
|
|
25
26
|
an object, that contains a byte array) and decode the result on the receiving
|
26
27
|
endpoint.
|
27
28
|
|
28
|
-
The JSON parsers can parse UTF-8, UTF-16BE, UTF-16LE, UTF-32BE, and UTF-32LE
|
29
|
-
JSON documents under Ruby 1.8. Under Ruby 1.9 they take advantage of Ruby's
|
30
|
-
M17n features and can parse all documents which have the correct
|
31
|
-
String#encoding set. If a document string has ASCII-8BIT as an encoding the
|
32
|
-
parser attempts to figure out which of the UTF encodings from above it is and
|
33
|
-
trys to parse it.
|
34
|
-
|
35
29
|
## Installation
|
36
30
|
|
37
31
|
It's recommended to use the extension variant of JSON, because it's faster than
|
@@ -40,113 +34,151 @@ for the latter.
|
|
40
34
|
|
41
35
|
Just type into the command line as root:
|
42
36
|
|
43
|
-
|
37
|
+
```
|
38
|
+
# rake install
|
39
|
+
```
|
44
40
|
|
45
41
|
The above command will build the extensions and install them on your system.
|
46
42
|
|
47
|
-
|
43
|
+
```
|
44
|
+
# rake install_pure
|
45
|
+
```
|
48
46
|
|
49
47
|
or
|
50
48
|
|
51
|
-
|
49
|
+
```
|
50
|
+
# ruby install.rb
|
51
|
+
```
|
52
52
|
|
53
53
|
will just install the pure ruby implementation of JSON.
|
54
54
|
|
55
55
|
If you use Rubygems you can type
|
56
56
|
|
57
|
-
|
57
|
+
```
|
58
|
+
# gem install json
|
59
|
+
```
|
58
60
|
|
59
61
|
instead, to install the newest JSON version.
|
60
62
|
|
61
63
|
There is also a pure ruby json only variant of the gem, that can be installed
|
62
64
|
with:
|
63
65
|
|
64
|
-
|
66
|
+
```
|
67
|
+
# gem install json_pure
|
68
|
+
```
|
65
69
|
|
66
70
|
## Compiling the extensions yourself
|
67
71
|
|
68
|
-
If you want to create the parser.c file from its parser.rl file or draw nice
|
72
|
+
If you want to create the `parser.c` file from its `parser.rl` file or draw nice
|
69
73
|
graphviz images of the state machines, you need ragel from:
|
70
74
|
http://www.complang.org/ragel/
|
71
75
|
|
72
76
|
## Usage
|
73
77
|
|
74
78
|
To use JSON you can
|
75
|
-
|
76
|
-
|
77
|
-
|
79
|
+
|
80
|
+
```ruby
|
81
|
+
require 'json'
|
82
|
+
```
|
83
|
+
|
84
|
+
to load the installed variant (either the extension `'json'` or the pure
|
85
|
+
variant `'json_pure'`). If you have installed the extension variant, you can
|
78
86
|
pick either the extension variant or the pure variant by typing
|
79
|
-
|
87
|
+
|
88
|
+
```ruby
|
89
|
+
require 'json/ext'
|
90
|
+
```
|
91
|
+
|
80
92
|
or
|
81
|
-
|
93
|
+
|
94
|
+
```ruby
|
95
|
+
require 'json/pure'
|
96
|
+
```
|
82
97
|
|
83
98
|
Now you can parse a JSON document into a ruby data structure by calling
|
84
99
|
|
85
|
-
|
100
|
+
```ruby
|
101
|
+
JSON.parse(document)
|
102
|
+
```
|
86
103
|
|
87
104
|
If you want to generate a JSON document from a ruby data structure call
|
88
|
-
|
105
|
+
```ruby
|
106
|
+
JSON.generate(data)
|
107
|
+
```
|
89
108
|
|
90
|
-
You can also use the
|
91
|
-
verbosely and nicely) or
|
109
|
+
You can also use the `pretty_generate` method (which formats the output more
|
110
|
+
verbosely and nicely) or `fast_generate` (which doesn't do any of the security
|
92
111
|
checks generate performs, e. g. nesting deepness checks).
|
93
112
|
|
94
|
-
To create a valid JSON document you have to make sure, that the output is
|
95
|
-
embedded in either a JSON array [] or a JSON object {}. The easiest way to do
|
96
|
-
this, is by putting your values in a Ruby Array or Hash instance.
|
97
|
-
|
98
113
|
There are also the JSON and JSON[] methods which use parse on a String or
|
99
114
|
generate a JSON document from an array or hash:
|
100
115
|
|
101
|
-
|
102
|
-
|
116
|
+
```ruby
|
117
|
+
document = JSON 'test' => 23 # => "{\"test\":23}"
|
118
|
+
document = JSON['test'] => 23 # => "{\"test\":23}"
|
119
|
+
```
|
103
120
|
|
104
121
|
and
|
105
122
|
|
106
|
-
|
107
|
-
|
123
|
+
```ruby
|
124
|
+
data = JSON '{"test":23}' # => {"test"=>23}
|
125
|
+
data = JSON['{"test":23}'] # => {"test"=>23}
|
126
|
+
```
|
108
127
|
|
109
128
|
You can choose to load a set of common additions to ruby core's objects if
|
110
129
|
you
|
111
|
-
|
130
|
+
|
131
|
+
```ruby
|
132
|
+
require 'json/add/core'
|
133
|
+
```
|
112
134
|
|
113
135
|
After requiring this you can, e. g., serialise/deserialise Ruby ranges:
|
114
136
|
|
115
|
-
|
137
|
+
```ruby
|
138
|
+
JSON JSON(1..10) # => 1..10
|
139
|
+
```
|
116
140
|
|
117
141
|
To find out how to add JSON support to other or your own classes, read the
|
118
142
|
section "More Examples" below.
|
119
143
|
|
120
144
|
To get the best compatibility to rails' JSON implementation, you can
|
121
|
-
require 'json/add/rails'
|
122
145
|
|
123
|
-
|
146
|
+
```ruby
|
147
|
+
require 'json/add/rails'
|
148
|
+
```
|
149
|
+
|
150
|
+
Both of the additions attempt to require `'json'` (like above) first, if it has
|
124
151
|
not been required yet.
|
125
152
|
|
126
153
|
## More Examples
|
127
154
|
|
128
155
|
To create a JSON document from a ruby data structure, you can call
|
129
|
-
JSON.generate like that:
|
156
|
+
`JSON.generate` like that:
|
130
157
|
|
131
|
-
|
132
|
-
|
158
|
+
```ruby
|
159
|
+
json = JSON.generate [1, 2, {"a"=>3.141}, false, true, nil, 4..10]
|
160
|
+
# => "[1,2,{\"a\":3.141},false,true,null,\"4..10\"]"
|
161
|
+
```
|
133
162
|
|
134
163
|
To get back a ruby data structure from a JSON document, you have to call
|
135
164
|
JSON.parse on it:
|
136
165
|
|
137
|
-
|
138
|
-
|
166
|
+
```ruby
|
167
|
+
JSON.parse json
|
168
|
+
# => [1, 2, {"a"=>3.141}, false, true, nil, "4..10"]
|
169
|
+
```
|
139
170
|
|
140
171
|
Note, that the range from the original data structure is a simple
|
141
172
|
string now. The reason for this is, that JSON doesn't support ranges
|
142
173
|
or arbitrary classes. In this case the json library falls back to call
|
143
|
-
Object#
|
174
|
+
`Object#to_json`, which is the same as `#to_s.to_json`.
|
144
175
|
|
145
176
|
It's possible to add JSON support serialization to arbitrary classes by
|
146
|
-
simply implementing a more specialized version of the
|
147
|
-
should return a JSON object (a hash converted to JSON with
|
148
|
-
this (don't forget the
|
177
|
+
simply implementing a more specialized version of the `#to_json method`, that
|
178
|
+
should return a JSON object (a hash converted to JSON with `#to_json`) like
|
179
|
+
this (don't forget the `*a` for all the arguments):
|
149
180
|
|
181
|
+
```ruby
|
150
182
|
class Range
|
151
183
|
def to_json(*a)
|
152
184
|
{
|
@@ -155,36 +187,42 @@ this (don't forget the *a for all the arguments):
|
|
155
187
|
}.to_json(*a)
|
156
188
|
end
|
157
189
|
end
|
190
|
+
```
|
158
191
|
|
159
|
-
The hash key
|
160
|
-
JSON representation later. In this case it's
|
161
|
-
the form
|
192
|
+
The hash key `json_class` is the class, that will be asked to deserialise the
|
193
|
+
JSON representation later. In this case it's `Range`, but any namespace of
|
194
|
+
the form `A::B` or `::A::B` will do. All other keys are arbitrary and can be
|
162
195
|
used to store the necessary data to configure the object to be deserialised.
|
163
196
|
|
164
|
-
If a the key
|
165
|
-
if the given class responds to the
|
197
|
+
If a the key `json_class` is found in a JSON object, the JSON parser checks
|
198
|
+
if the given class responds to the `json_create` class method. If so, it is
|
166
199
|
called with the JSON object converted to a Ruby hash. So a range can
|
167
|
-
be deserialised by implementing Range.
|
200
|
+
be deserialised by implementing `Range.json_create` like this:
|
168
201
|
|
202
|
+
```ruby
|
169
203
|
class Range
|
170
204
|
def self.json_create(o)
|
171
205
|
new(*o['data'])
|
172
206
|
end
|
173
207
|
end
|
208
|
+
```
|
174
209
|
|
175
210
|
Now it possible to serialise/deserialise ranges as well:
|
176
211
|
|
212
|
+
```ruby
|
177
213
|
json = JSON.generate [1, 2, {"a"=>3.141}, false, true, nil, 4..10]
|
178
214
|
# => "[1,2,{\"a\":3.141},false,true,null,{\"json_class\":\"Range\",\"data\":[4,10,false]}]"
|
179
215
|
JSON.parse json
|
180
216
|
# => [1, 2, {"a"=>3.141}, false, true, nil, 4..10]
|
217
|
+
```
|
181
218
|
|
182
|
-
JSON.generate always creates the shortest possible string representation of a
|
219
|
+
`JSON.generate` always creates the shortest possible string representation of a
|
183
220
|
ruby data structure in one line. This is good for data storage or network
|
184
221
|
protocols, but not so good for humans to read. Fortunately there's also
|
185
|
-
JSON.
|
222
|
+
`JSON.pretty_generate` (or `JSON.pretty_generate`) that creates a more readable
|
186
223
|
output:
|
187
224
|
|
225
|
+
```ruby
|
188
226
|
puts JSON.pretty_generate([1, 2, {"a"=>3.141}, false, true, nil, 4..10])
|
189
227
|
[
|
190
228
|
1,
|
@@ -204,12 +242,13 @@ output:
|
|
204
242
|
]
|
205
243
|
}
|
206
244
|
]
|
245
|
+
```
|
207
246
|
|
208
|
-
There are also the methods Kernel#j for generate, and Kernel#jj for
|
209
|
-
|
210
|
-
the pp library's pp methods.
|
247
|
+
There are also the methods `Kernel#j` for generate, and `Kernel#jj` for
|
248
|
+
`pretty_generate` output to the console, that work analogous to Core Ruby's `p` and
|
249
|
+
the `pp` library's `pp` methods.
|
211
250
|
|
212
|
-
The script tools/server.rb contains a small example if you want to test, how
|
251
|
+
The script `tools/server.rb` contains a small example if you want to test, how
|
213
252
|
receiving a JSON object from a webrick server in your browser with the
|
214
253
|
javasript prototype library http://www.prototypejs.org works.
|
215
254
|
|
@@ -219,67 +258,72 @@ I have created some benchmark results (see the benchmarks/data-p4-3Ghz
|
|
219
258
|
subdir of the package) for the JSON-parser to estimate the speed up in the C
|
220
259
|
extension:
|
221
260
|
|
261
|
+
```
|
222
262
|
Comparing times (call_time_mean):
|
223
263
|
1 ParserBenchmarkExt#parser 900 repeats:
|
224
|
-
553.922304770 ( real) -> 21.500x
|
264
|
+
553.922304770 ( real) -> 21.500x
|
225
265
|
0.001805307
|
226
266
|
2 ParserBenchmarkYAML#parser 1000 repeats:
|
227
|
-
224.513358139 ( real) -> 8.714x
|
267
|
+
224.513358139 ( real) -> 8.714x
|
228
268
|
0.004454078
|
229
269
|
3 ParserBenchmarkPure#parser 1000 repeats:
|
230
|
-
26.755020642 ( real) -> 1.038x
|
270
|
+
26.755020642 ( real) -> 1.038x
|
231
271
|
0.037376163
|
232
272
|
4 ParserBenchmarkRails#parser 1000 repeats:
|
233
|
-
25.763381731 ( real) -> 1.000x
|
273
|
+
25.763381731 ( real) -> 1.000x
|
234
274
|
0.038814780
|
235
275
|
calls/sec ( time) -> speed covers
|
236
276
|
secs/call
|
277
|
+
```
|
237
278
|
|
238
|
-
In the table above 1 is JSON::Ext::Parser
|
239
|
-
compatbile JSON document, 3 is is JSON::Pure::Parser
|
240
|
-
ActiveSupport::JSON.decode
|
279
|
+
In the table above 1 is `JSON::Ext::Parser`, 2 is `YAML.load` with YAML
|
280
|
+
compatbile JSON document, 3 is is `JSON::Pure::Parser`, and 4 is
|
281
|
+
`ActiveSupport::JSON.decode`. The ActiveSupport JSON-decoder converts the
|
241
282
|
input first to YAML and then uses the YAML-parser, the conversion seems to
|
242
|
-
slow it down so much that it is only as fast as the JSON::Pure::Parser
|
283
|
+
slow it down so much that it is only as fast as the `JSON::Pure::Parser`!
|
243
284
|
|
244
285
|
If you look at the benchmark data you can see that this is mostly caused by
|
245
286
|
the frequent high outliers - the median of the Rails-parser runs is still
|
246
|
-
overall smaller than the median of the JSON::Pure::Parser runs:
|
287
|
+
overall smaller than the median of the `JSON::Pure::Parser` runs:
|
247
288
|
|
289
|
+
```
|
248
290
|
Comparing times (call_time_median):
|
249
291
|
1 ParserBenchmarkExt#parser 900 repeats:
|
250
|
-
800.592479481 ( real) -> 26.936x
|
292
|
+
800.592479481 ( real) -> 26.936x
|
251
293
|
0.001249075
|
252
294
|
2 ParserBenchmarkYAML#parser 1000 repeats:
|
253
|
-
271.002390644 ( real) -> 9.118x
|
295
|
+
271.002390644 ( real) -> 9.118x
|
254
296
|
0.003690004
|
255
297
|
3 ParserBenchmarkRails#parser 1000 repeats:
|
256
|
-
30.227910865 ( real) -> 1.017x
|
298
|
+
30.227910865 ( real) -> 1.017x
|
257
299
|
0.033082008
|
258
300
|
4 ParserBenchmarkPure#parser 1000 repeats:
|
259
|
-
29.722384421 ( real) -> 1.000x
|
301
|
+
29.722384421 ( real) -> 1.000x
|
260
302
|
0.033644676
|
261
303
|
calls/sec ( time) -> speed covers
|
262
304
|
secs/call
|
305
|
+
```
|
263
306
|
|
264
|
-
I have benchmarked the JSON-Generator as well. This generated a few more
|
307
|
+
I have benchmarked the `JSON-Generator` as well. This generated a few more
|
265
308
|
values, because there are different modes that also influence the achieved
|
266
309
|
speed:
|
267
310
|
|
311
|
+
```
|
268
312
|
Comparing times (call_time_mean):
|
269
313
|
1 GeneratorBenchmarkExt#generator_fast 1000 repeats:
|
270
|
-
547.354332608 ( real) -> 15.090x
|
314
|
+
547.354332608 ( real) -> 15.090x
|
271
315
|
0.001826970
|
272
316
|
2 GeneratorBenchmarkExt#generator_safe 1000 repeats:
|
273
|
-
443.968212317 ( real) -> 12.240x
|
317
|
+
443.968212317 ( real) -> 12.240x
|
274
318
|
0.002252414
|
275
319
|
3 GeneratorBenchmarkExt#generator_pretty 900 repeats:
|
276
|
-
375.104545883 ( real) -> 10.341x
|
320
|
+
375.104545883 ( real) -> 10.341x
|
277
321
|
0.002665923
|
278
322
|
4 GeneratorBenchmarkPure#generator_fast 1000 repeats:
|
279
|
-
49.978706968 ( real) -> 1.378x
|
323
|
+
49.978706968 ( real) -> 1.378x
|
280
324
|
0.020008521
|
281
325
|
5 GeneratorBenchmarkRails#generator 1000 repeats:
|
282
|
-
38.531868759 ( real) -> 1.062x
|
326
|
+
38.531868759 ( real) -> 1.062x
|
283
327
|
0.025952543
|
284
328
|
6 GeneratorBenchmarkPure#generator_safe 1000 repeats:
|
285
329
|
36.927649925 ( real) -> 1.018x 7 (>=3859)
|
@@ -289,33 +333,35 @@ speed:
|
|
289
333
|
0.027569373
|
290
334
|
calls/sec ( time) -> speed covers
|
291
335
|
secs/call
|
336
|
+
```
|
292
337
|
|
293
|
-
In the table above 1-3 are JSON::Ext::Generator methods. 4, 6, and 7 are
|
294
|
-
JSON::Pure::Generator methods and 5 is the Rails JSON generator. It is now a
|
295
|
-
bit faster than the
|
338
|
+
In the table above 1-3 are `JSON::Ext::Generator` methods. 4, 6, and 7 are
|
339
|
+
`JSON::Pure::Generator` methods and 5 is the Rails JSON generator. It is now a
|
340
|
+
bit faster than the `generator_safe` and `generator_pretty` methods of the pure
|
296
341
|
variant but slower than the others.
|
297
342
|
|
298
|
-
To achieve the fastest JSON document output, you can use the
|
343
|
+
To achieve the fastest JSON document output, you can use the `fast_generate`
|
299
344
|
method. Beware, that this will disable the checking for circular Ruby data
|
300
345
|
structures, which may cause JSON to go into an infinite loop.
|
301
346
|
|
302
347
|
Here are the median comparisons for completeness' sake:
|
303
348
|
|
349
|
+
```
|
304
350
|
Comparing times (call_time_median):
|
305
351
|
1 GeneratorBenchmarkExt#generator_fast 1000 repeats:
|
306
|
-
708.258020939 ( real) -> 16.547x
|
352
|
+
708.258020939 ( real) -> 16.547x
|
307
353
|
0.001411915
|
308
354
|
2 GeneratorBenchmarkExt#generator_safe 1000 repeats:
|
309
|
-
569.105020353 ( real) -> 13.296x
|
355
|
+
569.105020353 ( real) -> 13.296x
|
310
356
|
0.001757145
|
311
357
|
3 GeneratorBenchmarkExt#generator_pretty 900 repeats:
|
312
|
-
482.825371244 ( real) -> 11.280x
|
358
|
+
482.825371244 ( real) -> 11.280x
|
313
359
|
0.002071142
|
314
360
|
4 GeneratorBenchmarkPure#generator_fast 1000 repeats:
|
315
|
-
62.717626652 ( real) -> 1.465x
|
361
|
+
62.717626652 ( real) -> 1.465x
|
316
362
|
0.015944481
|
317
363
|
5 GeneratorBenchmarkRails#generator 1000 repeats:
|
318
|
-
43.965681162 ( real) -> 1.027x
|
364
|
+
43.965681162 ( real) -> 1.027x
|
319
365
|
0.022745013
|
320
366
|
6 GeneratorBenchmarkPure#generator_safe 1000 repeats:
|
321
367
|
43.929073409 ( real) -> 1.026x 7 (>=3859)
|
@@ -325,6 +371,7 @@ Here are the median comparisons for completeness' sake:
|
|
325
371
|
0.023363113
|
326
372
|
calls/sec ( time) -> speed covers
|
327
373
|
secs/call
|
374
|
+
```
|
328
375
|
|
329
376
|
## Author
|
330
377
|
|