json 1.2.4 → 1.4.0

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.

data/README CHANGED
@@ -1,6 +1,4 @@
1
- == json - JSON Implementation for Ruby
2
-
3
- === Description
1
+ == Description
4
2
 
5
3
  This is a implementation of the JSON specification according to RFC 4627
6
4
  http://www.ietf.org/rfc/rfc4627.txt . Starting from version 1.0.0 on there
@@ -34,7 +32,7 @@ String#encoding set. If a document string has ASCII-8BIT as an encoding the
34
32
  parser attempts to figure out which of the UTF encodings from above it is and
35
33
  trys to parse it.
36
34
 
37
- === Installation
35
+ == Installation
38
36
 
39
37
  It's recommended to use the extension variant of JSON, because it's faster than
40
38
  the pure ruby variant. If you cannot build it on your system, you can settle
@@ -65,7 +63,7 @@ with:
65
63
 
66
64
  # gem install json_pure
67
65
 
68
- === Compiling the extensions yourself
66
+ == Compiling the extensions yourself
69
67
 
70
68
  If you want to build the extensions yourself you need rake:
71
69
 
@@ -82,7 +80,7 @@ If you want to create the parser.c file from its parser.rl file or draw nice
82
80
  graphviz images of the state machines, you need ragel from: http://www.cs.queensu.ca/~thurston/ragel
83
81
 
84
82
 
85
- === Usage
83
+ == Usage
86
84
 
87
85
  To use JSON you can
88
86
  require 'json'
@@ -136,7 +134,7 @@ To get the best compatibility to rails' JSON implementation, you can
136
134
  Both of the additions attempt to require 'json' (like above) first, if it has
137
135
  not been required yet.
138
136
 
139
- === More Examples
137
+ == More Examples
140
138
 
141
139
  To create a JSON document from a ruby data structure, you can call
142
140
  JSON.generate like that:
@@ -226,7 +224,7 @@ The script tools/server.rb contains a small example if you want to test, how
226
224
  receiving a JSON object from a webrick server in your browser with the
227
225
  javasript prototype library http://www.prototypejs.org works.
228
226
 
229
- === Speed Comparisons
227
+ == Speed Comparisons
230
228
 
231
229
  I have created some benchmark results (see the benchmarks/data-p4-3Ghz
232
230
  subdir of the package) for the JSON-parser to estimate the speed up in the C
@@ -339,17 +337,17 @@ Here are the median comparisons for completeness' sake:
339
337
  calls/sec ( time) -> speed covers
340
338
  secs/call
341
339
 
342
- === Author
340
+ == Author
343
341
 
344
342
  Florian Frank <mailto:flori@ping.de>
345
343
 
346
- === License
344
+ == License
347
345
 
348
346
  Ruby License, see the COPYING file included in the source distribution. The
349
347
  Ruby License includes the GNU General Public License (GPL), Version 2, so see
350
348
  the file GPL as well.
351
349
 
352
- === Download
350
+ == Download
353
351
 
354
352
  The latest version of this library can be downloaded at
355
353
 
data/Rakefile CHANGED
@@ -9,30 +9,29 @@ rescue LoadError
9
9
  puts "WARNING: rake-compiler is not installed. You will not be able to build the json gem until you install it."
10
10
  end
11
11
 
12
- require 'rake/clean'
13
- CLOBBER.include Dir['benchmarks/data/*.{dat,log}']
14
-
15
12
  require 'rbconfig'
16
13
  include Config
17
14
 
15
+ require 'rake/clean'
16
+ CLOBBER.include Dir['benchmarks/data/*.{dat,log}'], FileList['**/*.rbc']
17
+ CLEAN.include FileList['diagrams/*.*'], 'doc', 'coverage', 'tmp',
18
+ FileList["ext/**/{Makefile,mkmf.log}"],
19
+ FileList["{ext,lib}/**/*.{so,bundle,#{CONFIG['DLEXT']},o,obj,pdb,lib,manifest,exp,def}"]
20
+
18
21
  MAKE = ENV['MAKE'] || %w[gmake make].find { |c| system(c, '-v') }
19
22
  PKG_NAME = 'json'
23
+ PKG_TITLE = 'JSON Implementation for Ruby'
20
24
  PKG_VERSION = File.read('VERSION').chomp
21
25
  PKG_FILES = FileList["**/*"].exclude(/CVS|pkg|tmp|coverage|Makefile|\.nfs\./).exclude(/\.(so|bundle|o|#{CONFIG['DLEXT']})$/)
22
26
  EXT_ROOT_DIR = 'ext/json/ext'
23
- EXT_PARSER_DIR = "#{EXT_ROOT_DIR}/parser"
24
27
  EXT_PARSER_DL = "#{EXT_ROOT_DIR}/parser.#{CONFIG['DLEXT']}"
25
- EXT_PARSER_SRC = "#{EXT_PARSER_DIR}/parser.c"
28
+ EXT_PARSER_SRC = "#{EXT_ROOT_DIR}/parser.c"
26
29
  PKG_FILES << EXT_PARSER_SRC
27
- EXT_GENERATOR_DIR = "#{EXT_ROOT_DIR}/generator"
28
30
  EXT_GENERATOR_DL = "#{EXT_ROOT_DIR}/generator.#{CONFIG['DLEXT']}"
29
- EXT_GENERATOR_SRC = "#{EXT_GENERATOR_DIR}/generator.c"
31
+ EXT_GENERATOR_SRC = "#{EXT_ROOT_DIR}/generator.c"
30
32
  RAGEL_CODEGEN = %w[rlcodegen rlgen-cd ragel].find { |c| system(c, '-v') }
31
33
  RAGEL_DOTGEN = %w[rlgen-dot rlgen-cd ragel].find { |c| system(c, '-v') }
32
- RAGEL_PATH = "#{EXT_PARSER_DIR}/parser.rl"
33
- CLEAN.include FileList['diagrams/*.*'], 'doc', 'coverage', 'tmp',
34
- FileList["ext/**/{Makefile,mkmf.log}"],
35
- FileList["{ext,lib}/**/*.{so,bundle,#{CONFIG['DLEXT']},o,obj,pdb,lib,manifest,exp,def}"]
34
+ RAGEL_PATH = "#{EXT_ROOT_DIR}/parser.rl"
36
35
 
37
36
  def myruby(*args, &block)
38
37
  @myruby ||= File.join(CONFIG['bindir'], CONFIG['ruby_install_name'])
@@ -74,19 +73,17 @@ desc "Compiling extension"
74
73
  task :compile_ext => [ EXT_PARSER_DL, EXT_GENERATOR_DL ]
75
74
 
76
75
  file EXT_PARSER_DL => EXT_PARSER_SRC do
77
- cd EXT_PARSER_DIR do
78
- myruby 'extconf.rb'
76
+ cd EXT_ROOT_DIR do
77
+ myruby 'extconf_parser.rb'
79
78
  sh MAKE
80
79
  end
81
- cp "#{EXT_PARSER_DIR}/parser.#{CONFIG['DLEXT']}", EXT_ROOT_DIR
82
80
  end
83
81
 
84
82
  file EXT_GENERATOR_DL => EXT_GENERATOR_SRC do
85
- cd EXT_GENERATOR_DIR do
86
- myruby 'extconf.rb'
83
+ cd EXT_ROOT_DIR do
84
+ myruby 'extconf_generator.rb'
87
85
  sh MAKE
88
86
  end
89
- cp "#{EXT_GENERATOR_DIR}/generator.#{CONFIG['DLEXT']}", EXT_ROOT_DIR
90
87
  end
91
88
 
92
89
  desc "Generate parser with ragel"
@@ -97,7 +94,7 @@ task :ragel_clean do
97
94
  end
98
95
 
99
96
  file EXT_PARSER_SRC => RAGEL_PATH do
100
- cd EXT_PARSER_DIR do
97
+ cd EXT_ROOT_DIR do
101
98
  if RAGEL_CODEGEN == 'ragel'
102
99
  sh "ragel parser.rl -G2 -o parser.c"
103
100
  else
@@ -158,12 +155,14 @@ desc "Benchmarking parser"
158
155
  task :benchmark_parser do
159
156
  ENV['RUBYOPT'] = "-Ilib:ext #{ENV['RUBYOPT']}"
160
157
  myruby 'benchmarks/parser_benchmark.rb'
158
+ myruby 'benchmarks/parser2_benchmark.rb'
161
159
  end
162
160
 
163
161
  desc "Benchmarking generator"
164
162
  task :benchmark_generator do
165
163
  ENV['RUBYOPT'] = "-Ilib:ext #{ENV['RUBYOPT']}"
166
164
  myruby 'benchmarks/generator_benchmark.rb'
165
+ myruby 'benchmarks/generator2_benchmark.rb'
167
166
  end
168
167
 
169
168
  desc "Benchmarking library"
@@ -171,14 +170,14 @@ task :benchmark => [ :benchmark_parser, :benchmark_generator ]
171
170
 
172
171
  desc "Create RDOC documentation"
173
172
  task :doc => [ :version, EXT_PARSER_SRC ] do
174
- sh "rdoc -o doc -m README README lib/json.rb #{FileList['lib/json/**/*.rb']} #{EXT_PARSER_SRC} #{EXT_GENERATOR_SRC}"
173
+ sh "rdoc -o doc -t '#{PKG_TITLE}' -m README README lib/json.rb #{FileList['lib/json/**/*.rb']} #{EXT_PARSER_SRC} #{EXT_GENERATOR_SRC}"
175
174
  end
176
175
 
177
176
  if defined?(Gem) and defined?(Rake::GemPackageTask) and defined?(Rake::ExtensionTask)
178
177
  spec_pure = Gem::Specification.new do |s|
179
178
  s.name = 'json_pure'
180
179
  s.version = PKG_VERSION
181
- s.summary = "A JSON implementation in Ruby"
180
+ s.summary = PKG_TITLE
182
181
  s.description = "This is a JSON implementation in pure Ruby."
183
182
 
184
183
  s.files = PKG_FILES
@@ -192,7 +191,7 @@ if defined?(Gem) and defined?(Rake::GemPackageTask) and defined?(Rake::Extension
192
191
  s.has_rdoc = true
193
192
  s.extra_rdoc_files << 'README'
194
193
  s.rdoc_options <<
195
- '--title' << 'JSON -- A JSON implemention' << '--main' << 'README'
194
+ '--title' << 'JSON implemention for ruby' << '--main' << 'README'
196
195
  s.test_files.concat Dir['tests/*.rb']
197
196
 
198
197
  s.author = "Florian Frank"
@@ -209,12 +208,12 @@ if defined?(Gem) and defined?(Rake::GemPackageTask) and defined?(Rake::Extension
209
208
  spec_ext = Gem::Specification.new do |s|
210
209
  s.name = 'json'
211
210
  s.version = PKG_VERSION
212
- s.summary = "A JSON implementation as a Ruby extension"
211
+ s.summary = PKG_TITLE
213
212
  s.description = "This is a JSON implementation as a Ruby extension in C."
214
213
 
215
214
  s.files = PKG_FILES
216
215
 
217
- s.extensions = FileList['ext/**/extconf.rb']
216
+ s.extensions = FileList['ext/**/extconf_*.rb']
218
217
 
219
218
  s.require_path = EXT_ROOT_DIR
220
219
  s.require_paths << 'ext'
@@ -227,7 +226,7 @@ if defined?(Gem) and defined?(Rake::GemPackageTask) and defined?(Rake::Extension
227
226
  s.has_rdoc = true
228
227
  s.extra_rdoc_files << 'README'
229
228
  s.rdoc_options <<
230
- '--title' << 'JSON -- A JSON implemention' << '--main' << 'README'
229
+ '--title' << 'JSON implemention for Ruby' << '--main' << 'README'
231
230
  s.test_files.concat Dir['tests/*.rb']
232
231
 
233
232
  s.author = "Florian Frank"
@@ -243,19 +242,21 @@ if defined?(Gem) and defined?(Rake::GemPackageTask) and defined?(Rake::Extension
243
242
 
244
243
  Rake::ExtensionTask.new do |ext|
245
244
  ext.name = 'parser'
245
+ ext.config_script = 'extconf_parser.rb'
246
246
  ext.gem_spec = spec_ext
247
247
  ext.cross_compile = true
248
248
  ext.cross_platform = %w[i386-mswin32 i386-mingw32]
249
- ext.ext_dir = 'ext/json/ext/parser'
249
+ ext.ext_dir = 'ext/json/ext'
250
250
  ext.lib_dir = 'lib/json/ext'
251
251
  end
252
252
 
253
253
  Rake::ExtensionTask.new do |ext|
254
254
  ext.name = 'generator'
255
+ ext.config_script = 'extconf_generator.rb'
255
256
  ext.gem_spec = spec_ext
256
257
  ext.cross_compile = true
257
258
  ext.cross_platform = %w[i386-mswin32 i386-mingw32]
258
- ext.ext_dir = 'ext/json/ext/generator'
259
+ ext.ext_dir = 'ext/json/ext'
259
260
  ext.lib_dir = 'lib/json/ext'
260
261
  end
261
262
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.2.4
1
+ 1.4.0
@@ -0,0 +1,222 @@
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
+ when 'yajl'
16
+ require 'yajl'
17
+ require 'yajl/json_gem'
18
+ require 'stringio'
19
+ end
20
+
21
+ module JSON
22
+ def self.[](*) end
23
+ end
24
+
25
+ module Generator2BenchmarkCommon
26
+ include JSON
27
+
28
+ def setup
29
+ @big = eval File.read(File.join(File.dirname(__FILE__), 'ohai.ruby'))
30
+ end
31
+
32
+ def generic_reset_method
33
+ @result and @result.size >= 16 or raise @result.to_s
34
+ end
35
+ end
36
+
37
+ module JSONGeneratorCommon
38
+ include Generator2BenchmarkCommon
39
+
40
+ def benchmark_generator_fast
41
+ @result = JSON.fast_generate(@big)
42
+ end
43
+
44
+ alias reset_benchmark_generator_fast generic_reset_method
45
+
46
+ def benchmark_generator_safe
47
+ @result = JSON.generate(@big)
48
+ end
49
+
50
+ alias reset_benchmark_generator_safe generic_reset_method
51
+
52
+ def benchmark_generator_pretty
53
+ @result = JSON.pretty_generate(@big)
54
+ end
55
+
56
+ alias reset_benchmark_generator_pretty generic_reset_method
57
+
58
+ def benchmark_generator_ascii
59
+ @result = JSON.generate(@big, :ascii_only => true)
60
+ end
61
+
62
+ alias reset_benchmark_generator_ascii generic_reset_method
63
+ end
64
+
65
+ class Generator2BenchmarkExt < Bullshit::RepeatCase
66
+ include JSONGeneratorCommon
67
+
68
+ warmup yes
69
+ iterations 2000
70
+
71
+ truncate_data do
72
+ enabled false
73
+ alpha_level 0.05
74
+ window_size 50
75
+ slope_angle 0.1
76
+ end
77
+
78
+ autocorrelation do
79
+ alpha_level 0.05
80
+ max_lags 50
81
+ file yes
82
+ end
83
+
84
+
85
+ output_dir File.join(File.dirname(__FILE__), 'data')
86
+ output_filename benchmark_name + '.log'
87
+ data_file yes
88
+ histogram yes
89
+ end
90
+
91
+ class Generator2BenchmarkPure < Bullshit::RepeatCase
92
+ include JSONGeneratorCommon
93
+
94
+ warmup yes
95
+ iterations 400
96
+
97
+ truncate_data do
98
+ enabled false
99
+ alpha_level 0.05
100
+ window_size 50
101
+ slope_angle 0.1
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
+ end
115
+
116
+ class Generator2BenchmarkRails < Bullshit::RepeatCase
117
+ include Generator2BenchmarkCommon
118
+
119
+ warmup yes
120
+ iterations 400
121
+
122
+ truncate_data do
123
+ enabled false
124
+ alpha_level 0.05
125
+ window_size 50
126
+ slope_angle 0.1
127
+ end
128
+
129
+ autocorrelation do
130
+ alpha_level 0.05
131
+ max_lags 50
132
+ file yes
133
+ end
134
+
135
+ output_dir File.join(File.dirname(__FILE__), 'data')
136
+ output_filename benchmark_name + '.log'
137
+ data_file yes
138
+ histogram yes
139
+
140
+ def benchmark_generator
141
+ @result = @big.to_json
142
+ end
143
+
144
+ alias reset_benchmark_generator generic_reset_method
145
+ end
146
+
147
+ class Generator2BenchmarkYajl < Bullshit::RepeatCase
148
+ include Generator2BenchmarkCommon
149
+
150
+ warmup yes
151
+ iterations 2000
152
+
153
+ truncate_data do
154
+ enabled false
155
+ alpha_level 0.05
156
+ window_size 50
157
+ slope_angle 0.1
158
+ end
159
+
160
+ autocorrelation do
161
+ alpha_level 0.05
162
+ max_lags 50
163
+ file yes
164
+ end
165
+
166
+ output_dir File.join(File.dirname(__FILE__), 'data')
167
+ output_filename benchmark_name + '.log'
168
+ data_file yes
169
+ histogram yes
170
+
171
+ def benchmark_generator
172
+ output = StringIO.new
173
+ Yajl::Encoder.new.encode(@big, output)
174
+ @result = output.string
175
+ end
176
+
177
+ def benchmark_generator_gem_api
178
+ @result = @big.to_json
179
+ end
180
+
181
+ def reset_benchmark_generator
182
+ generic_reset_method
183
+ end
184
+ end
185
+
186
+ if $0 == __FILE__
187
+ Bullshit::Case.autorun false
188
+
189
+ case ARGV.first
190
+ when 'ext'
191
+ Generator2BenchmarkExt.run
192
+ when 'pure'
193
+ Generator2BenchmarkPure.run
194
+ when 'rails'
195
+ Generator2BenchmarkRails.run
196
+ when 'yajl'
197
+ Generator2BenchmarkYajl.run
198
+ else
199
+ system "#{RAKE_PATH} clean"
200
+ system "#{RUBY_PATH} #$0 rails"
201
+ system "#{RUBY_PATH} #$0 pure"
202
+ system "#{RAKE_PATH} compile_ext"
203
+ system "#{RUBY_PATH} #$0 ext"
204
+ system "#{RUBY_PATH} #$0 yajl"
205
+ Bullshit.compare do
206
+ output_filename File.join(File.dirname(__FILE__), 'data', 'Generator2BenchmarkComparison.log')
207
+
208
+ benchmark Generator2BenchmarkExt, :generator_fast, :load => yes
209
+ benchmark Generator2BenchmarkExt, :generator_safe, :load => yes
210
+ benchmark Generator2BenchmarkExt, :generator_pretty, :load => yes
211
+ benchmark Generator2BenchmarkExt, :generator_ascii, :load => yes
212
+ benchmark Generator2BenchmarkPure, :generator_fast, :load => yes
213
+ benchmark Generator2BenchmarkPure, :generator_safe, :load => yes
214
+ benchmark Generator2BenchmarkPure, :generator_pretty, :load => yes
215
+ benchmark Generator2BenchmarkPure, :generator_ascii, :load => yes
216
+ benchmark Generator2BenchmarkRails, :generator, :load => yes
217
+ benchmark Generator2BenchmarkYajl, :generator, :load => yes
218
+ benchmark Generator2BenchmarkYajl, :generator_gem_api, :load => yes
219
+ end
220
+ end
221
+ end
222
+