json 1.0.3-mswin32
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/CHANGES +32 -0
- data/GPL +340 -0
- data/README +77 -0
- data/Rakefile +304 -0
- data/TODO +1 -0
- data/VERSION +1 -0
- data/benchmarks/benchmark.txt +133 -0
- data/benchmarks/benchmark_generator.rb +44 -0
- data/benchmarks/benchmark_parser.rb +22 -0
- data/benchmarks/benchmark_rails.rb +26 -0
- data/bin/edit_json.rb +11 -0
- data/bin/prettify_json.rb +75 -0
- data/data/example.json +1 -0
- data/data/index.html +37 -0
- data/data/prototype.js +2515 -0
- data/ext/json/ext/generator.so +0 -0
- data/ext/json/ext/generator/extconf.rb +9 -0
- data/ext/json/ext/generator/generator.c +729 -0
- data/ext/json/ext/generator/unicode.c +184 -0
- data/ext/json/ext/generator/unicode.h +40 -0
- data/ext/json/ext/parser.so +0 -0
- data/ext/json/ext/parser/extconf.rb +9 -0
- data/ext/json/ext/parser/parser.c +1554 -0
- data/ext/json/ext/parser/parser.rl +515 -0
- data/ext/json/ext/parser/unicode.c +156 -0
- data/ext/json/ext/parser/unicode.h +44 -0
- data/install.rb +26 -0
- data/lib/json.rb +205 -0
- data/lib/json/Array.xpm +21 -0
- data/lib/json/FalseClass.xpm +21 -0
- data/lib/json/Hash.xpm +21 -0
- data/lib/json/Key.xpm +73 -0
- data/lib/json/NilClass.xpm +21 -0
- data/lib/json/Numeric.xpm +28 -0
- data/lib/json/String.xpm +96 -0
- data/lib/json/TrueClass.xpm +21 -0
- data/lib/json/common.rb +184 -0
- data/lib/json/editor.rb +1207 -0
- data/lib/json/ext.rb +13 -0
- data/lib/json/json.xpm +1499 -0
- data/lib/json/pure.rb +75 -0
- data/lib/json/pure/generator.rb +321 -0
- data/lib/json/pure/parser.rb +214 -0
- data/lib/json/version.rb +8 -0
- data/tests/fixtures/fail1.json +1 -0
- data/tests/fixtures/fail10.json +1 -0
- data/tests/fixtures/fail11.json +1 -0
- data/tests/fixtures/fail12.json +1 -0
- data/tests/fixtures/fail13.json +1 -0
- data/tests/fixtures/fail14.json +1 -0
- data/tests/fixtures/fail15.json +1 -0
- data/tests/fixtures/fail16.json +1 -0
- data/tests/fixtures/fail17.json +1 -0
- data/tests/fixtures/fail19.json +1 -0
- data/tests/fixtures/fail2.json +1 -0
- data/tests/fixtures/fail20.json +1 -0
- data/tests/fixtures/fail21.json +1 -0
- data/tests/fixtures/fail22.json +1 -0
- data/tests/fixtures/fail23.json +1 -0
- data/tests/fixtures/fail24.json +1 -0
- data/tests/fixtures/fail25.json +1 -0
- data/tests/fixtures/fail26.json +1 -0
- data/tests/fixtures/fail27.json +2 -0
- data/tests/fixtures/fail28.json +2 -0
- data/tests/fixtures/fail3.json +1 -0
- data/tests/fixtures/fail4.json +1 -0
- data/tests/fixtures/fail5.json +1 -0
- data/tests/fixtures/fail6.json +1 -0
- data/tests/fixtures/fail7.json +1 -0
- data/tests/fixtures/fail8.json +1 -0
- data/tests/fixtures/fail9.json +1 -0
- data/tests/fixtures/pass1.json +56 -0
- data/tests/fixtures/pass18.json +1 -0
- data/tests/fixtures/pass2.json +1 -0
- data/tests/fixtures/pass3.json +6 -0
- data/tests/runner.rb +24 -0
- data/tests/test_json.rb +236 -0
- data/tests/test_json_addition.rb +94 -0
- data/tests/test_json_fixtures.rb +30 -0
- data/tests/test_json_generate.rb +81 -0
- data/tests/test_json_unicode.rb +58 -0
- data/tools/fuzz.rb +131 -0
- data/tools/server.rb +62 -0
- metadata +149 -0
data/Rakefile
ADDED
@@ -0,0 +1,304 @@
|
|
1
|
+
# vim: set et sw=2 ts=2:
|
2
|
+
|
3
|
+
require 'rake/gempackagetask'
|
4
|
+
require 'rake/clean'
|
5
|
+
|
6
|
+
require 'rbconfig'
|
7
|
+
include Config
|
8
|
+
|
9
|
+
ON_WINDOWS = RUBY_PLATFORM =~ /mswin32/i
|
10
|
+
PKG_NAME = 'json'
|
11
|
+
PKG_VERSION = File.read('VERSION').chomp
|
12
|
+
PKG_FILES = FileList["**/*"].exclude(/CVS|pkg|coverage|Makefile/).exclude(/\.(so|bundle|o|#{CONFIG['DLEXT']})$/)
|
13
|
+
EXT_ROOT_DIR = 'ext/json/ext'
|
14
|
+
EXT_PARSER_DIR = "#{EXT_ROOT_DIR}/parser"
|
15
|
+
EXT_PARSER_DL = "#{EXT_ROOT_DIR}/parser.#{CONFIG['DLEXT']}"
|
16
|
+
EXT_PARSER_SRC = "#{EXT_PARSER_DIR}/parser.c"
|
17
|
+
PKG_FILES << EXT_PARSER_SRC
|
18
|
+
EXT_GENERATOR_DIR = "#{EXT_ROOT_DIR}/generator"
|
19
|
+
EXT_GENERATOR_DL = "#{EXT_ROOT_DIR}/generator.#{CONFIG['DLEXT']}"
|
20
|
+
EXT_GENERATOR_SRC = "#{EXT_GENERATOR_DIR}/generator.c"
|
21
|
+
RAGEL_CODEGEN = %w[rlcodegen rlgen-cd].find { |c| system(c, '-v') }
|
22
|
+
RAGEL_PATH = "#{EXT_PARSER_DIR}/parser.rl"
|
23
|
+
CLEAN.include 'doc', 'coverage', FileList['diagrams/*.*'],
|
24
|
+
FileList["ext/**/*.{so,bundle,#{CONFIG['DLEXT']},o,obj,pdb,lib,manifest,exp,def}"],
|
25
|
+
FileList["ext/**/Makefile"]
|
26
|
+
|
27
|
+
|
28
|
+
desc "Installing library (pure)"
|
29
|
+
task :install_pure => :version do
|
30
|
+
ruby 'install.rb'
|
31
|
+
end
|
32
|
+
|
33
|
+
task :install_ext_really do
|
34
|
+
sitearchdir = CONFIG["sitearchdir"]
|
35
|
+
cd 'ext' do
|
36
|
+
for file in Dir["json/ext/*.#{CONFIG['DLEXT']}"]
|
37
|
+
d = File.join(sitearchdir, file)
|
38
|
+
mkdir_p File.dirname(d)
|
39
|
+
install(file, d)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
desc "Installing library (extension)"
|
45
|
+
task :install_ext => [ :compile, :install_pure, :install_ext_really ]
|
46
|
+
|
47
|
+
task :install => :install_ext
|
48
|
+
|
49
|
+
desc "Compiling extension"
|
50
|
+
task :compile => [ EXT_PARSER_DL, EXT_GENERATOR_DL ]
|
51
|
+
|
52
|
+
file EXT_PARSER_DL => EXT_PARSER_SRC do
|
53
|
+
cd EXT_PARSER_DIR do
|
54
|
+
ruby 'extconf.rb'
|
55
|
+
if ON_WINDOWS
|
56
|
+
sh 'nmake'
|
57
|
+
sh "mt -manifest parser.#{CONFIG['DLEXT']}.manifest -outputresource:parser.#{CONFIG['DLEXT']};2"
|
58
|
+
else
|
59
|
+
sh 'make'
|
60
|
+
end
|
61
|
+
end
|
62
|
+
cp "#{EXT_PARSER_DIR}/parser.#{CONFIG['DLEXT']}", EXT_ROOT_DIR
|
63
|
+
end
|
64
|
+
|
65
|
+
file EXT_GENERATOR_DL => EXT_GENERATOR_SRC do
|
66
|
+
cd EXT_GENERATOR_DIR do
|
67
|
+
ruby 'extconf.rb'
|
68
|
+
if ON_WINDOWS
|
69
|
+
sh 'nmake'
|
70
|
+
sh "mt -manifest generator.#{CONFIG['DLEXT']}.manifest -outputresource:generator.#{CONFIG['DLEXT']};2"
|
71
|
+
else
|
72
|
+
sh 'make'
|
73
|
+
end
|
74
|
+
end
|
75
|
+
cp "#{EXT_GENERATOR_DIR}/generator.#{CONFIG['DLEXT']}", EXT_ROOT_DIR
|
76
|
+
end
|
77
|
+
|
78
|
+
desc "Generate parser with ragel"
|
79
|
+
task :ragel => EXT_PARSER_SRC
|
80
|
+
|
81
|
+
task :ragel_clean do
|
82
|
+
rm_rf EXT_PARSER_SRC
|
83
|
+
end
|
84
|
+
|
85
|
+
file EXT_PARSER_SRC => RAGEL_PATH do
|
86
|
+
cd EXT_PARSER_DIR do
|
87
|
+
sh "ragel parser.rl | #{RAGEL_CODEGEN} -G2"
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
desc "Generate diagrams of ragel parser (ps)"
|
92
|
+
task :ragel_dot_ps do
|
93
|
+
root = 'diagrams'
|
94
|
+
specs = []
|
95
|
+
File.new(RAGEL_PATH).grep(/^\s*machine\s*(\S+);\s*$/) { specs << $1 }
|
96
|
+
for s in specs
|
97
|
+
sh "ragel #{RAGEL_PATH} -S#{s} | #{RAGEL_CODEGEN} -p -V|dot -Tps -o#{root}/#{s}.ps"
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
desc "Generate diagrams of ragel parser (png)"
|
102
|
+
task :ragel_dot_png do
|
103
|
+
root = 'diagrams'
|
104
|
+
specs = []
|
105
|
+
File.new(RAGEL_PATH).grep(/^\s*machine\s*(\S+);\s*$/) { specs << $1 }
|
106
|
+
for s in specs
|
107
|
+
sh "ragel #{RAGEL_PATH} -S#{s} | #{RAGEL_CODEGEN} -p -V|dot -Tpng -o#{root}/#{s}.png"
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
desc "Generate diagrams of ragel parser"
|
112
|
+
task :ragel_dot => [ :ragel_dot_png, :ragel_dot_ps ]
|
113
|
+
|
114
|
+
desc "Testing library (pure ruby)"
|
115
|
+
task :test_pure => :clean do
|
116
|
+
ruby '-I lib tests/runner.rb'
|
117
|
+
end
|
118
|
+
|
119
|
+
desc "Testing library (extension)"
|
120
|
+
task :test_ext => :compile do
|
121
|
+
ruby '-I ext:lib tests/runner.rb'
|
122
|
+
end
|
123
|
+
|
124
|
+
desc "Benchmarking parser (pure)"
|
125
|
+
task :benchmark_parser_pure do
|
126
|
+
ruby '-I lib benchmarks/benchmark_parser.rb'
|
127
|
+
end
|
128
|
+
|
129
|
+
desc "Benchmarking generator (pure)"
|
130
|
+
task :benchmark_generator_pure do
|
131
|
+
ruby '-I lib benchmarks/benchmark_generator.rb'
|
132
|
+
ruby 'benchmarks/benchmark_rails.rb'
|
133
|
+
end
|
134
|
+
|
135
|
+
desc "Benchmarking library (pure)"
|
136
|
+
task :benchmark_pure => [ :benchmark_parser_pure, :benchmark_generator_pure ]
|
137
|
+
|
138
|
+
desc "Benchmarking parser (extension)"
|
139
|
+
task :benchmark_parser_ext => :compile do
|
140
|
+
ruby '-I ext:lib benchmarks/benchmark_parser.rb'
|
141
|
+
end
|
142
|
+
|
143
|
+
desc "Benchmarking generator (extension)"
|
144
|
+
task :benchmark_generator_ext => :compile do
|
145
|
+
ruby '-I ext:lib benchmarks/benchmark_generator.rb'
|
146
|
+
ruby 'benchmarks/benchmark_rails.rb'
|
147
|
+
end
|
148
|
+
|
149
|
+
desc "Benchmarking library (extension)"
|
150
|
+
task :benchmark_ext => [ :benchmark_parser_ext, :benchmark_generator_ext ]
|
151
|
+
|
152
|
+
task :benchmark do
|
153
|
+
puts "Benchmarking extension variant"
|
154
|
+
Rake::Task[:benchmark_ext].invoke
|
155
|
+
puts "Benchmarking pure variant"
|
156
|
+
Rake::Task[:benchmark_pure].invoke
|
157
|
+
end
|
158
|
+
|
159
|
+
desc "Testing library with coverage" # XXX broken
|
160
|
+
task :coverage do
|
161
|
+
system 'RUBYOPT="" rcov -x tests -Ilib tests/runner.rb'
|
162
|
+
end
|
163
|
+
|
164
|
+
desc "Create RDOC documentation"
|
165
|
+
task :doc => [ :version, EXT_PARSER_SRC ] do
|
166
|
+
sh "rdoc -m JSON -d -S -o doc #{FileList['lib/**/*.rb']} #{EXT_PARSER_SRC} #{EXT_GENERATOR_SRC}"
|
167
|
+
end
|
168
|
+
|
169
|
+
spec_pure = Gem::Specification.new do |s|
|
170
|
+
s.name = 'json_pure'
|
171
|
+
s.version = PKG_VERSION
|
172
|
+
s.summary = "A JSON implementation in Ruby"
|
173
|
+
s.description = ""
|
174
|
+
|
175
|
+
s.files = PKG_FILES
|
176
|
+
|
177
|
+
s.require_path = 'lib'
|
178
|
+
|
179
|
+
s.bindir = "bin"
|
180
|
+
s.executables = ["edit_json.rb"]
|
181
|
+
s.default_executable = "edit_json.rb"
|
182
|
+
|
183
|
+
s.has_rdoc = true
|
184
|
+
s.rdoc_options <<
|
185
|
+
'--title' << 'JSON -- A JSON implemention' <<
|
186
|
+
'--main' << 'JSON' << '--line-numbers'
|
187
|
+
s.test_files << 'tests/runner.rb'
|
188
|
+
|
189
|
+
s.author = "Florian Frank"
|
190
|
+
s.email = "flori@ping.de"
|
191
|
+
s.homepage = "http://json.rubyforge.org"
|
192
|
+
s.rubyforge_project = "json"
|
193
|
+
end
|
194
|
+
|
195
|
+
Rake::GemPackageTask.new(spec_pure) do |pkg|
|
196
|
+
pkg.need_tar = true
|
197
|
+
pkg.package_files += PKG_FILES
|
198
|
+
end
|
199
|
+
|
200
|
+
spec_ext = Gem::Specification.new do |s|
|
201
|
+
s.name = 'json'
|
202
|
+
s.version = PKG_VERSION
|
203
|
+
s.summary = "A JSON implementation as a Ruby extension"
|
204
|
+
s.description = ""
|
205
|
+
|
206
|
+
s.files = PKG_FILES
|
207
|
+
|
208
|
+
s.extensions <<
|
209
|
+
"#{EXT_PARSER_DIR}/extconf.rb" <<
|
210
|
+
"#{EXT_GENERATOR_DIR}/extconf.rb"
|
211
|
+
|
212
|
+
s.require_path = EXT_ROOT_DIR
|
213
|
+
s.require_paths << 'ext'
|
214
|
+
s.require_paths << 'lib'
|
215
|
+
|
216
|
+
s.bindir = "bin"
|
217
|
+
s.executables = ["edit_json.rb"]
|
218
|
+
s.default_executable = "edit_json.rb"
|
219
|
+
|
220
|
+
s.has_rdoc = true
|
221
|
+
s.rdoc_options <<
|
222
|
+
'--title' << 'JSON -- A JSON implemention' <<
|
223
|
+
'--main' << 'JSON' << '--line-numbers'
|
224
|
+
s.test_files << 'tests/runner.rb'
|
225
|
+
|
226
|
+
s.author = "Florian Frank"
|
227
|
+
s.email = "flori@ping.de"
|
228
|
+
s.homepage = "http://json.rubyforge.org"
|
229
|
+
s.rubyforge_project = "json"
|
230
|
+
end
|
231
|
+
|
232
|
+
Rake::GemPackageTask.new(spec_ext) do |pkg|
|
233
|
+
pkg.need_tar = true
|
234
|
+
pkg.package_files += PKG_FILES
|
235
|
+
end
|
236
|
+
|
237
|
+
task :package_win => :compile do
|
238
|
+
mkdir_p 'pkg'
|
239
|
+
spec_win_ext = Gem::Specification.new do |s|
|
240
|
+
s.name = 'json'
|
241
|
+
s.platform = Gem::Platform::WIN32
|
242
|
+
s.version = PKG_VERSION
|
243
|
+
s.summary = "A JSON implementation as a Ruby extension"
|
244
|
+
s.description = ""
|
245
|
+
|
246
|
+
s.files = PKG_FILES.to_a <<
|
247
|
+
"#{EXT_ROOT_DIR}/parser.#{CONFIG['DLEXT']}" <<
|
248
|
+
"#{EXT_ROOT_DIR}/generator.#{CONFIG['DLEXT']}"
|
249
|
+
|
250
|
+
s.require_path = EXT_ROOT_DIR
|
251
|
+
s.require_paths << 'ext'
|
252
|
+
s.require_paths << 'lib'
|
253
|
+
|
254
|
+
s.bindir = "bin"
|
255
|
+
s.executables = ["edit_json.rb"]
|
256
|
+
s.default_executable = "edit_json.rb"
|
257
|
+
|
258
|
+
s.has_rdoc = true
|
259
|
+
s.rdoc_options <<
|
260
|
+
'--title' << 'JSON -- A JSON implemention' <<
|
261
|
+
'--main' << 'JSON' << '--line-numbers'
|
262
|
+
s.test_files << 'tests/runner.rb'
|
263
|
+
|
264
|
+
s.author = "Florian Frank"
|
265
|
+
s.email = "flori@ping.de"
|
266
|
+
s.homepage = "http://json.rubyforge.org"
|
267
|
+
s.rubyforge_project = "json"
|
268
|
+
end
|
269
|
+
|
270
|
+
gem_file = "json-#{spec_win_ext.version}-#{spec_win_ext.platform}.gem"
|
271
|
+
Gem::Builder.new(spec_win_ext).build
|
272
|
+
mv gem_file, 'pkg'
|
273
|
+
end
|
274
|
+
|
275
|
+
task :mrproper => [ :ragel_clean, :clean ] do
|
276
|
+
for dir in [ EXT_PARSER_DIR, EXT_GENERATOR_DIR ]
|
277
|
+
cd(dir) { rm_f 'Makefile' }
|
278
|
+
end
|
279
|
+
end
|
280
|
+
|
281
|
+
desc m = "Writing version information for #{PKG_VERSION}"
|
282
|
+
task :version do
|
283
|
+
puts m
|
284
|
+
File.open(File.join('lib', 'json', 'version.rb'), 'w') do |v|
|
285
|
+
v.puts <<EOT
|
286
|
+
module JSON
|
287
|
+
# JSON version
|
288
|
+
VERSION = '#{PKG_VERSION}'
|
289
|
+
VERSION_ARRAY = VERSION.split(/\\./).map { |x| x.to_i } # :nodoc:
|
290
|
+
VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
|
291
|
+
VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
|
292
|
+
VERSION_BUILD = VERSION_ARRAY[2] # :nodoc:
|
293
|
+
end
|
294
|
+
EOT
|
295
|
+
end
|
296
|
+
end
|
297
|
+
|
298
|
+
if ON_WINDOWS
|
299
|
+
task :release => [ :version, :clean, :compile, :package_win ]
|
300
|
+
else
|
301
|
+
task :release => [ :version, :mrproper, :package ]
|
302
|
+
end
|
303
|
+
|
304
|
+
task :default => [ :version, :compile ]
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.0.3
|
@@ -0,0 +1,133 @@
|
|
1
|
+
(in /home/flori/json)
|
2
|
+
Ragel Code Generator version 5.17 January 2007
|
3
|
+
Copyright (c) 2001-2006 by Adrian Thurston
|
4
|
+
Benchmarking extension variant
|
5
|
+
First run for warmup.
|
6
|
+
Running 'BC_Parser' for a duration of 10 secs per method:
|
7
|
+
real total utime stime cutime cstime
|
8
|
+
parser: 10.005944 10.010000 9.970000 0.040000 0.000000 0.000000
|
9
|
+
5091 508.591409 0.001966
|
10
|
+
calls calls/sec secs/call
|
11
|
+
--------------------------------------------------------------------------------
|
12
|
+
Running 'BC_Parser' for a duration of 10 secs per method:
|
13
|
+
real total utime stime cutime cstime
|
14
|
+
parser: 10.006881 10.000000 9.950000 0.050000 0.000000 0.000000
|
15
|
+
5055 505.500000 0.001978
|
16
|
+
calls calls/sec secs/call
|
17
|
+
--------------------------------------------------------------------------------
|
18
|
+
================================================================================
|
19
|
+
|
20
|
+
|
21
|
+
[null,false,true,"f\u00d6\u00df\u00c4r",["n\u20acst\u20acd",true],{"quux":true,"foo\u00df":"b\u00e4r"}]
|
22
|
+
First run for warmup.
|
23
|
+
Running 'BC_Generator' for a duration of 10 secs per method:
|
24
|
+
real total utime stime cutime cstime
|
25
|
+
generator_pretty: 10.001066 10.010000 9.990000 0.020000 0.000000 0.000000
|
26
|
+
3492 348.851149 0.002867
|
27
|
+
generator_fast : 10.002910 10.000000 9.980000 0.020000 0.000000 0.000000
|
28
|
+
5416 541.600000 0.001846
|
29
|
+
generator_safe : 10.003107 10.010000 10.000000 0.010000 0.000000 0.000000
|
30
|
+
4926 492.107892 0.002032
|
31
|
+
calls calls/sec secs/call
|
32
|
+
--------------------------------------------------------------------------------
|
33
|
+
Running 'BC_Generator' for a duration of 10 secs per method:
|
34
|
+
real total utime stime cutime cstime
|
35
|
+
generator_pretty: 10.009150 10.010000 10.010000 0.000000 0.000000 0.000000
|
36
|
+
3511 350.749251 0.002851
|
37
|
+
generator_fast : 10.014407 10.020000 10.020000 0.000000 0.000000 0.000000
|
38
|
+
5411 540.019960 0.001852
|
39
|
+
generator_safe : 10.010055 10.000000 10.000000 0.000000 0.000000 0.000000
|
40
|
+
4933 493.300000 0.002027
|
41
|
+
calls calls/sec secs/call
|
42
|
+
--------------------------------------------------------------------------------
|
43
|
+
================================================================================
|
44
|
+
|
45
|
+
Comparison in BC_Generator:
|
46
|
+
secs/call speed
|
47
|
+
generator_fast : 0.002 -> 1.540x
|
48
|
+
generator_safe : 0.002 -> 1.406x
|
49
|
+
generator_pretty: 0.003 -> 1.000x
|
50
|
+
--------------------------------------------------------------------------------
|
51
|
+
|
52
|
+
[null, false, true, "f\u00d6\u00df\u00c4r", ["n\u20acst\u20acd", true], {quux: true, "foo\u00df": "b\u00e4r"}]
|
53
|
+
First run for warmup.
|
54
|
+
Running 'BC_Rails' for a duration of 10 secs per method:
|
55
|
+
real total utime stime cutime cstime
|
56
|
+
generator: 10.026043 10.020000 10.020000 0.000000 0.000000 0.000000
|
57
|
+
239 23.852295 0.041925
|
58
|
+
calls calls/sec secs/call
|
59
|
+
--------------------------------------------------------------------------------
|
60
|
+
Running 'BC_Rails' for a duration of 10 secs per method:
|
61
|
+
real total utime stime cutime cstime
|
62
|
+
generator: 10.010931 10.020000 10.010000 0.010000 0.000000 0.000000
|
63
|
+
238 23.752495 0.042101
|
64
|
+
calls calls/sec secs/call
|
65
|
+
--------------------------------------------------------------------------------
|
66
|
+
================================================================================
|
67
|
+
|
68
|
+
|
69
|
+
Benchmarking pure variant
|
70
|
+
First run for warmup.
|
71
|
+
Running 'BC_Parser' for a duration of 10 secs per method:
|
72
|
+
real total utime stime cutime cstime
|
73
|
+
parser: 10.022352 10.030000 10.020000 0.010000 0.000000 0.000000
|
74
|
+
288 28.713858 0.034826
|
75
|
+
calls calls/sec secs/call
|
76
|
+
--------------------------------------------------------------------------------
|
77
|
+
Running 'BC_Parser' for a duration of 10 secs per method:
|
78
|
+
real total utime stime cutime cstime
|
79
|
+
parser: 10.006552 10.000000 10.000000 0.000000 0.000000 0.000000
|
80
|
+
289 28.900000 0.034602
|
81
|
+
calls calls/sec secs/call
|
82
|
+
--------------------------------------------------------------------------------
|
83
|
+
================================================================================
|
84
|
+
|
85
|
+
|
86
|
+
[null,false,true,"f\u00d6\u00df\u00c4r",["n\u20acst\u20acd",true],{"quux":true,"foo\u00df":"b\u00e4r"}]
|
87
|
+
First run for warmup.
|
88
|
+
Running 'BC_Generator' for a duration of 10 secs per method:
|
89
|
+
real total utime stime cutime cstime
|
90
|
+
generator_fast : 10.011644 10.010000 10.010000 0.000000 0.000000 0.000000
|
91
|
+
411 41.058941 0.024355
|
92
|
+
generator_safe : 10.007100 10.010000 10.010000 0.000000 0.000000 0.000000
|
93
|
+
352 35.164835 0.028438
|
94
|
+
generator_pretty: 10.008156 10.010000 10.010000 0.000000 0.000000 0.000000
|
95
|
+
341 34.065934 0.029355
|
96
|
+
calls calls/sec secs/call
|
97
|
+
--------------------------------------------------------------------------------
|
98
|
+
Running 'BC_Generator' for a duration of 10 secs per method:
|
99
|
+
real total utime stime cutime cstime
|
100
|
+
generator_fast : 10.005185 10.010000 10.010000 0.000000 0.000000 0.000000
|
101
|
+
411 41.058941 0.024355
|
102
|
+
generator_safe : 10.006932 10.010000 10.010000 0.000000 0.000000 0.000000
|
103
|
+
351 35.064935 0.028519
|
104
|
+
generator_pretty: 10.007414 10.000000 10.000000 0.000000 0.000000 0.000000
|
105
|
+
340 34.000000 0.029412
|
106
|
+
calls calls/sec secs/call
|
107
|
+
--------------------------------------------------------------------------------
|
108
|
+
================================================================================
|
109
|
+
|
110
|
+
Comparison in BC_Generator:
|
111
|
+
secs/call speed
|
112
|
+
generator_fast : 0.024 -> 1.208x
|
113
|
+
generator_safe : 0.029 -> 1.031x
|
114
|
+
generator_pretty: 0.029 -> 1.000x
|
115
|
+
--------------------------------------------------------------------------------
|
116
|
+
|
117
|
+
[null, false, true, "f\u00d6\u00df\u00c4r", ["n\u20acst\u20acd", true], {quux: true, "foo\u00df": "b\u00e4r"}]
|
118
|
+
First run for warmup.
|
119
|
+
Running 'BC_Rails' for a duration of 10 secs per method:
|
120
|
+
real total utime stime cutime cstime
|
121
|
+
generator: 10.005748 10.000000 10.000000 0.000000 0.000000 0.000000
|
122
|
+
240 24.000000 0.041667
|
123
|
+
calls calls/sec secs/call
|
124
|
+
--------------------------------------------------------------------------------
|
125
|
+
Running 'BC_Rails' for a duration of 10 secs per method:
|
126
|
+
real total utime stime cutime cstime
|
127
|
+
generator: 10.006764 10.010000 10.010000 0.000000 0.000000 0.000000
|
128
|
+
239 23.876124 0.041883
|
129
|
+
calls calls/sec secs/call
|
130
|
+
--------------------------------------------------------------------------------
|
131
|
+
================================================================================
|
132
|
+
|
133
|
+
|
@@ -0,0 +1,44 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bullshit'
|
4
|
+
$KCODE='utf8'
|
5
|
+
require 'json'
|
6
|
+
|
7
|
+
class BC_Generator < Bullshit::TimeCase
|
8
|
+
include JSON
|
9
|
+
|
10
|
+
warmup true
|
11
|
+
duration 10
|
12
|
+
|
13
|
+
def setup
|
14
|
+
a = [ nil, false, true, "fÖßÄr", [ "n€st€d", true ], { "fooß" => "bär", "quux" => true } ]
|
15
|
+
puts JSON[a]
|
16
|
+
@big = a * 100
|
17
|
+
end
|
18
|
+
|
19
|
+
def benchmark_generator_fast
|
20
|
+
@result = JSON.fast_generate(@big)
|
21
|
+
end
|
22
|
+
|
23
|
+
def reset_benchmark_generator_fast
|
24
|
+
@result and @result.size > 2 + 6 * @big.size or raise @result.to_s
|
25
|
+
end
|
26
|
+
|
27
|
+
def benchmark_generator_safe
|
28
|
+
@result = JSON.generate(@big)
|
29
|
+
end
|
30
|
+
|
31
|
+
def reset_benchmark_generator_safe
|
32
|
+
@result and @result.size > 2 + 6 * @big.size or raise @result.to_s
|
33
|
+
end
|
34
|
+
|
35
|
+
def benchmark_generator_pretty
|
36
|
+
@result = JSON.pretty_generate(@big)
|
37
|
+
end
|
38
|
+
|
39
|
+
def reset_benchmark_generator_pretty
|
40
|
+
@result and @result.size > 2 + 6 * @big.size or raise @result.to_s
|
41
|
+
end
|
42
|
+
|
43
|
+
compare :generator_fast, :generator_safe, :generator_pretty
|
44
|
+
end
|