json 1.1.3 → 1.1.4

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of json might be problematic. Click here for more details.

Files changed (67) hide show
  1. data/CHANGES +9 -0
  2. data/Rakefile +47 -53
  3. data/VERSION +1 -1
  4. data/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkComparison.log +52 -0
  5. data/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_fast-autocorrelation.dat +1000 -0
  6. data/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_fast.dat +1001 -0
  7. data/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_pretty-autocorrelation.dat +900 -0
  8. data/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_pretty.dat +901 -0
  9. data/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_safe-autocorrelation.dat +1000 -0
  10. data/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_safe.dat +1001 -0
  11. data/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt.log +261 -0
  12. data/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_fast-autocorrelation.dat +1000 -0
  13. data/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_fast.dat +1001 -0
  14. data/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_pretty-autocorrelation.dat +1000 -0
  15. data/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_pretty.dat +1001 -0
  16. data/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_safe-autocorrelation.dat +1000 -0
  17. data/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_safe.dat +1001 -0
  18. data/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure.log +262 -0
  19. data/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkRails#generator-autocorrelation.dat +1000 -0
  20. data/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkRails#generator.dat +1001 -0
  21. data/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkRails.log +82 -0
  22. data/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkComparison.log +34 -0
  23. data/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkExt#parser-autocorrelation.dat +900 -0
  24. data/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkExt#parser.dat +901 -0
  25. data/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkExt.log +81 -0
  26. data/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkPure#parser-autocorrelation.dat +1000 -0
  27. data/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkPure#parser.dat +1001 -0
  28. data/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkPure.log +82 -0
  29. data/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkRails#parser-autocorrelation.dat +1000 -0
  30. data/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkRails#parser.dat +1001 -0
  31. data/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkRails.log +82 -0
  32. data/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkYAML#parser-autocorrelation.dat +1000 -0
  33. data/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkYAML#parser.dat +1001 -0
  34. data/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkYAML.log +82 -0
  35. data/benchmarks/generator_benchmark.rb +162 -0
  36. data/benchmarks/parser_benchmark.rb +193 -0
  37. data/bin/edit_json.rb +0 -1
  38. data/bin/prettify_json.rb +0 -1
  39. data/doc-templates/main.txt +284 -0
  40. data/ext/json/ext/generator/extconf.rb +2 -0
  41. data/ext/json/ext/generator/generator.c +62 -18
  42. data/ext/json/ext/parser/extconf.rb +2 -0
  43. data/ext/json/ext/parser/parser.c +128 -81
  44. data/ext/json/ext/parser/parser.rl +31 -7
  45. data/ext/json/ext/parser/unicode.c +4 -4
  46. data/lib/json.rb +0 -221
  47. data/lib/json/add/core.rb +1 -1
  48. data/lib/json/editor.rb +11 -2
  49. data/lib/json/ext.rb +2 -0
  50. data/lib/json/pure.rb +2 -0
  51. data/lib/json/pure/generator.rb +77 -41
  52. data/lib/json/pure/parser.rb +6 -2
  53. data/lib/json/version.rb +1 -1
  54. data/tests/test_json.rb +7 -4
  55. data/tests/test_json_addition.rb +8 -5
  56. data/tests/test_json_fixtures.rb +6 -2
  57. data/tests/test_json_generate.rb +8 -2
  58. data/tests/test_json_rails.rb +30 -2
  59. data/tests/test_json_unicode.rb +8 -7
  60. data/tools/fuzz.rb +0 -1
  61. data/tools/server.rb +0 -1
  62. metadata +46 -9
  63. data/benchmarks/benchmark.txt +0 -133
  64. data/benchmarks/benchmark_generator.rb +0 -48
  65. data/benchmarks/benchmark_parser.rb +0 -26
  66. data/benchmarks/benchmark_rails.rb +0 -26
  67. data/tests/runner.rb +0 -25
@@ -0,0 +1,82 @@
1
+ ========================== 2009-04-01T16:46:41 CEST ===========================
2
+ Benchmarking on ruby 1.8.6 (2008-08-11 patchlevel 287) [i686-linux].
3
+ Running 'ParserBenchmarkYAML' for 1000 iterations/method (compare_time=real)
4
+ ===============================================================================
5
+
6
+ This first run is only for warmup.
7
+ ParserBenchmarkYAML#parser:
8
+ real total user system
9
+ sum 4.506546021 4.490000000 4.480000000 0.010000000
10
+ min 0.003598928 0.000000000 0.000000000 0.000000000
11
+ std- 0.000288588 -0.001817113 -0.001826296 -0.000306228
12
+ mean 0.004506546 0.004490000 0.004480000 0.000010000
13
+ std+ 0.008724504 0.010797113 0.010786296 0.000326228
14
+ max 0.042540073 0.040000000 0.040000000 0.010000000
15
+ std 0.004217958 0.006307113 0.006306296 0.000316228
16
+ std% 93.596247306 140.470232048 140.765535944 3162.277660168
17
+ harm 0.003882332 nan nan nan
18
+ geo 0.004019118 0.000000000 0.000000000 0.000000000
19
+ q1 0.003660917 0.000000000 0.000000000 0.000000000
20
+ med 0.003705978 0.000000000 0.000000000 0.000000000
21
+ q3 0.003748715 0.010000000 0.010000000 0.000000000
22
+ 1000 221.89943 0.004506546
23
+ calls calls/sec secs/call
24
+
25
+ 0.04059 -|
26
+ 0.03670 -|
27
+ 0.03280 -|
28
+ 0.02891 -|*
29
+ 0.02502 -|
30
+ 0.02112 -|
31
+ 0.01723 -|
32
+ 0.01333 -|
33
+ 0.00944 -|
34
+ 0.00555 -|**************************************************
35
+
36
+ Outliers detected with box plot algo (median=0.00371, iqr=0.00009, factor=3.00):
37
+ high=56 very_high=119
38
+
39
+ Ljung-Box statistics: q=433.20488 (alpha=0.05, df=50).
40
+ 1.00000 >= 0.95000 => Autocorrelation was detected.
41
+
42
+ ParserBenchmarkYAML#parser:
43
+ real total user system
44
+ sum 4.454077959 4.430000000 4.420000000 0.010000000
45
+ min 0.003582954 0.000000000 0.000000000 0.000000000
46
+ std- 0.000263948 -0.001903657 -0.001912749 -0.000306228
47
+ mean 0.004454078 0.004430000 0.004420000 0.000010000
48
+ std+ 0.008644208 0.010763657 0.010752749 0.000326228
49
+ max 0.035927057 0.040000000 0.040000000 0.010000000
50
+ std 0.004190130 0.006333657 0.006332749 0.000316228
51
+ std% 94.074019869 142.971948832 143.274853190 3162.277660168
52
+ harm 0.003836471 nan nan nan
53
+ geo 0.003968258 0.000000000 0.000000000 0.000000000
54
+ q1 0.003650367 0.000000000 0.000000000 0.000000000
55
+ med 0.003690004 0.000000000 0.000000000 0.000000000
56
+ q3 0.003731966 0.010000000 0.010000000 0.000000000
57
+ 1000 224.51336 0.004454078
58
+ calls calls/sec secs/call
59
+
60
+ 0.03431 -|
61
+ 0.03108 -|*
62
+ 0.02784 -|*
63
+ 0.02461 -|
64
+ 0.02137 -|
65
+ 0.01814 -|
66
+ 0.01490 -|
67
+ 0.01167 -|
68
+ 0.00843 -|
69
+ 0.00520 -|**************************************************
70
+
71
+ Outliers detected with box plot algo (median=0.00369, iqr=0.00008, factor=3.00):
72
+ high=58 very_high=100
73
+
74
+ Ljung-Box statistics: q=451.12745 (alpha=0.05, df=50).
75
+ 1.00000 >= 0.95000 => Autocorrelation was detected.
76
+
77
+ No initial data truncated.
78
+ => System may have been in a steady state from the beginning.
79
+ ========================== 2009-04-01T16:46:54 CEST ===========================
80
+
81
+ Writing measurement data file '/data/scm/json/benchmarks/data/ParserBenchmarkYAML#parser.dat'.
82
+ Writing autocorrelation plot file '/data/scm/json/benchmarks/data/ParserBenchmarkYAML#parser-autocorrelation.dat'.
@@ -0,0 +1,162 @@
1
+ #!/usr/bin/env ruby
2
+ # CODING: UTF-8
3
+
4
+ require 'rbconfig'
5
+ RUBY_PATH=File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name'])
6
+ RAKE_PATH=File.join(Config::CONFIG['bindir'], 'rake')
7
+ require 'bullshit'
8
+ case ARGV.first
9
+ when 'ext'
10
+ require 'json/ext'
11
+ when 'pure'
12
+ require 'json/pure'
13
+ when 'rails'
14
+ require 'active_support'
15
+ end
16
+
17
+ module JSON
18
+ def self.[](*) end
19
+ end
20
+
21
+ module GeneratorBenchmarkCommon
22
+ include JSON
23
+
24
+ def setup
25
+ a = [ nil, false, true, "fÖßÄr", [ "n€st€d", true ], { "fooß" => "bär", "quux" => true } ]
26
+ puts a.to_json
27
+ @big = a * 100
28
+ end
29
+
30
+ def generic_reset_method
31
+ @result and @result.size > 2 + 6 * @big.size or raise @result.to_s
32
+ end
33
+ end
34
+
35
+ module JSONGeneratorCommon
36
+ include GeneratorBenchmarkCommon
37
+
38
+ def benchmark_generator_fast
39
+ @result = JSON.fast_generate(@big)
40
+ end
41
+
42
+ alias reset_benchmark_generator_fast generic_reset_method
43
+
44
+ def benchmark_generator_safe
45
+ @result = JSON.generate(@big)
46
+ end
47
+
48
+ alias reset_benchmark_generator_safe generic_reset_method
49
+
50
+ def benchmark_generator_pretty
51
+ @result = JSON.pretty_generate(@big)
52
+ end
53
+
54
+ alias reset_benchmark_generator_pretty generic_reset_method
55
+ end
56
+
57
+ class GeneratorBenchmarkExt < Bullshit::RepeatCase
58
+ include JSONGeneratorCommon
59
+
60
+ warmup yes
61
+ iterations 1000
62
+
63
+ truncate_data do
64
+ alpha_level 0.05
65
+ window_size 50
66
+ end
67
+
68
+ autocorrelation do
69
+ alpha_level 0.05
70
+ max_lags 50
71
+ file yes
72
+ end
73
+
74
+
75
+ output_dir File.join(File.dirname(__FILE__), 'data')
76
+ output_filename benchmark_name + '.log'
77
+ data_file yes
78
+ histogram yes
79
+ end
80
+
81
+ class GeneratorBenchmarkPure < Bullshit::RepeatCase
82
+ include JSONGeneratorCommon
83
+
84
+ warmup yes
85
+ iterations 1000
86
+
87
+ truncate_data do
88
+ alpha_level 0.05
89
+ window_size 50
90
+ end
91
+
92
+ autocorrelation do
93
+ alpha_level 0.05
94
+ max_lags 50
95
+ file yes
96
+ end
97
+
98
+ output_dir File.join(File.dirname(__FILE__), 'data')
99
+ output_filename benchmark_name + '.log'
100
+ data_file yes
101
+ histogram yes
102
+ end
103
+
104
+ class GeneratorBenchmarkRails < Bullshit::RepeatCase
105
+ include GeneratorBenchmarkCommon
106
+
107
+ warmup yes
108
+ iterations 1000
109
+
110
+ truncate_data do
111
+ alpha_level 0.05
112
+ window_size 50
113
+ end
114
+
115
+ autocorrelation do
116
+ alpha_level 0.05
117
+ max_lags 50
118
+ file yes
119
+ end
120
+
121
+ output_dir File.join(File.dirname(__FILE__), 'data')
122
+ output_filename benchmark_name + '.log'
123
+ data_file yes
124
+ histogram yes
125
+
126
+ def benchmark_generator
127
+ @result = @big.to_json
128
+ end
129
+
130
+ alias reset_benchmark_generator generic_reset_method
131
+ end
132
+
133
+ if $0 == __FILE__
134
+ Bullshit::Case.autorun false
135
+
136
+ case ARGV.first
137
+ when 'ext'
138
+ GeneratorBenchmarkExt.run
139
+ when 'pure'
140
+ GeneratorBenchmarkPure.run
141
+ when 'rails'
142
+ GeneratorBenchmarkRails.run
143
+ else
144
+ system "#{RAKE_PATH} clean"
145
+ system "#{RUBY_PATH} #$0 rails"
146
+ system "#{RUBY_PATH} #$0 pure"
147
+ system "#{RAKE_PATH} compile"
148
+ system "#{RUBY_PATH} #$0 ext"
149
+ Bullshit.compare do
150
+ output_filename File.join(File.dirname(__FILE__), 'data', 'GeneratorBenchmarkComparison.log')
151
+
152
+ benchmark GeneratorBenchmarkExt, :generator_fast, :load => yes
153
+ benchmark GeneratorBenchmarkExt, :generator_safe, :load => yes
154
+ benchmark GeneratorBenchmarkExt, :generator_pretty, :load => yes
155
+ benchmark GeneratorBenchmarkPure, :generator_fast, :load => yes
156
+ benchmark GeneratorBenchmarkPure, :generator_safe, :load => yes
157
+ benchmark GeneratorBenchmarkPure, :generator_pretty, :load => yes
158
+ benchmark GeneratorBenchmarkRails, :generator, :load => yes
159
+ end
160
+ end
161
+ end
162
+
@@ -0,0 +1,193 @@
1
+ #!/usr/bin/env ruby
2
+ # CODING: UTF-8
3
+
4
+ require 'rbconfig'
5
+ RUBY_PATH=File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name'])
6
+ RAKE_PATH=File.join(Config::CONFIG['bindir'], 'rake')
7
+ require 'bullshit'
8
+ case ARGV.first
9
+ when 'ext'
10
+ require 'json/ext'
11
+ when 'pure'
12
+ require 'json/pure'
13
+ when 'yaml'
14
+ require 'yaml'
15
+ require 'json/pure'
16
+ when 'rails'
17
+ require 'active_support'
18
+ require 'json/pure'
19
+ else
20
+ require 'json/pure'
21
+ end
22
+
23
+ module ParserBenchmarkCommon
24
+ include JSON
25
+
26
+ def setup
27
+ a = [ nil, false, true, "fÖß\nÄr", [ "n€st€d", true ], { "fooß" => "bär", "qu\r\nux" => true } ]
28
+ @big = a * 100
29
+ @json = JSON.generate(@big)
30
+ end
31
+
32
+ def generic_reset_method
33
+ @result == @big or raise "not equal"
34
+ end
35
+ end
36
+
37
+ class ParserBenchmarkExt < Bullshit::RepeatCase
38
+ include ParserBenchmarkCommon
39
+
40
+ warmup yes
41
+ iterations 1000
42
+
43
+ truncate_data do
44
+ alpha_level 0.05
45
+ window_size 50
46
+ end
47
+
48
+ autocorrelation do
49
+ alpha_level 0.05
50
+ max_lags 50
51
+ file yes
52
+ end
53
+
54
+ output_dir File.join(File.dirname(__FILE__), 'data')
55
+ output_filename benchmark_name + '.log'
56
+ data_file yes
57
+ histogram yes
58
+
59
+ def benchmark_parser
60
+ @result = JSON.parse(@json)
61
+ end
62
+
63
+ alias reset_parser generic_reset_method
64
+ end
65
+
66
+ class ParserBenchmarkPure < Bullshit::RepeatCase
67
+ include ParserBenchmarkCommon
68
+
69
+ warmup yes
70
+ iterations 1000
71
+
72
+ truncate_data do
73
+ alpha_level 0.05
74
+ window_size 50
75
+ end
76
+
77
+ autocorrelation do
78
+ alpha_level 0.05
79
+ max_lags 50
80
+ file yes
81
+ end
82
+
83
+ output_dir File.join(File.dirname(__FILE__), 'data')
84
+ output_filename benchmark_name + '.log'
85
+ data_file yes
86
+ histogram yes
87
+
88
+ def benchmark_parser
89
+ @result = JSON.parse(@json)
90
+ end
91
+
92
+ alias reset_parser generic_reset_method
93
+ end
94
+
95
+ class ParserBenchmarkYAML < Bullshit::RepeatCase
96
+ warmup yes
97
+ iterations 1000
98
+
99
+ truncate_data do
100
+ alpha_level 0.05
101
+ window_size 50
102
+ end
103
+
104
+ autocorrelation do
105
+ alpha_level 0.05
106
+ max_lags 50
107
+ file yes
108
+ end
109
+
110
+ output_dir File.join(File.dirname(__FILE__), 'data')
111
+ output_filename benchmark_name + '.log'
112
+ data_file yes
113
+ histogram yes
114
+
115
+ def setup
116
+ a = [ nil, false, true, "fÖß\nÄr", [ "n€st€d", true ], { "fooß" => "bär", "qu\r\nux" => true } ]
117
+ @big = a * 100
118
+ @json = JSON.pretty_generate(@big)
119
+ end
120
+
121
+ def benchmark_parser
122
+ @result = YAML.load(@json)
123
+ end
124
+
125
+ def generic_reset_method
126
+ @result == @big or raise "not equal"
127
+ end
128
+ end
129
+
130
+ class ParserBenchmarkRails < Bullshit::RepeatCase
131
+ warmup yes
132
+ iterations 1000
133
+
134
+ truncate_data do
135
+ alpha_level 0.05
136
+ window_size 50
137
+ end
138
+
139
+ autocorrelation do
140
+ alpha_level 0.05
141
+ max_lags 50
142
+ file yes
143
+ end
144
+
145
+ output_dir File.join(File.dirname(__FILE__), 'data')
146
+ output_filename benchmark_name + '.log'
147
+ data_file yes
148
+ histogram yes
149
+
150
+ def setup
151
+ a = [ nil, false, true, "fÖß\nÄr", [ "n€st€d", true ], { "fooß" => "bär", "qu\r\nux" => true } ]
152
+ @big = a * 100
153
+ @json = JSON.generate(@big)
154
+ end
155
+
156
+ def benchmark_parser
157
+ @result = ActiveSupport::JSON.decode(@json)
158
+ end
159
+
160
+ def generic_reset_method
161
+ @result == @big or raise "not equal"
162
+ end
163
+ end
164
+
165
+ if $0 == __FILE__
166
+ Bullshit::Case.autorun false
167
+
168
+ case ARGV.first
169
+ when 'ext'
170
+ ParserBenchmarkExt.run
171
+ when 'pure'
172
+ ParserBenchmarkPure.run
173
+ when 'yaml'
174
+ ParserBenchmarkYAML.run
175
+ when 'rails'
176
+ ParserBenchmarkRails.run
177
+ else
178
+ system "#{RAKE_PATH} clean"
179
+ system "#{RUBY_PATH} #$0 yaml"
180
+ system "#{RUBY_PATH} #$0 rails"
181
+ system "#{RUBY_PATH} #$0 pure"
182
+ system "#{RAKE_PATH} compile"
183
+ system "#{RUBY_PATH} #$0 ext"
184
+ Bullshit.compare do
185
+ output_filename File.join(File.dirname(__FILE__), 'data', 'ParserBenchmarkComparison.log')
186
+
187
+ benchmark ParserBenchmarkExt, :parser, :load => yes
188
+ benchmark ParserBenchmarkPure, :parser, :load => yes
189
+ benchmark ParserBenchmarkYAML, :parser, :load => yes
190
+ benchmark ParserBenchmarkRails, :parser, :load => yes
191
+ end
192
+ end
193
+ end
@@ -1,5 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
- $KCODE = 'U'
3
2
  require 'json/editor'
4
3
 
5
4
  filename, encoding = ARGV
@@ -1,6 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- $KCODE = 'U'
4
3
  require 'json'
5
4
  require 'fileutils'
6
5
  include FileUtils