yajl-ruby 1.0.0-x86-mswin32-60

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

Potentially problematic release.


This version of yajl-ruby might be problematic. Click here for more details.

Files changed (152) hide show
  1. data/.gitignore +12 -0
  2. data/.rspec +2 -0
  3. data/CHANGELOG.md +327 -0
  4. data/Gemfile +3 -0
  5. data/MIT-LICENSE +20 -0
  6. data/README.md +362 -0
  7. data/Rakefile +2 -0
  8. data/benchmark/encode.rb +72 -0
  9. data/benchmark/encode_json_and_marshal.rb +42 -0
  10. data/benchmark/encode_json_and_yaml.rb +53 -0
  11. data/benchmark/http.rb +32 -0
  12. data/benchmark/parse.rb +94 -0
  13. data/benchmark/parse_json_and_marshal.rb +50 -0
  14. data/benchmark/parse_json_and_yaml.rb +55 -0
  15. data/benchmark/parse_stream.rb +54 -0
  16. data/benchmark/subjects/item.json +1 -0
  17. data/benchmark/subjects/ohai.json +1216 -0
  18. data/benchmark/subjects/ohai.marshal_dump +0 -0
  19. data/benchmark/subjects/ohai.yml +975 -0
  20. data/benchmark/subjects/twitter_search.json +1 -0
  21. data/benchmark/subjects/twitter_stream.json +430 -0
  22. data/benchmark/subjects/unicode.json +1 -0
  23. data/examples/encoding/chunked_encoding.rb +27 -0
  24. data/examples/encoding/one_shot.rb +13 -0
  25. data/examples/encoding/to_an_io.rb +12 -0
  26. data/examples/http/twitter_search_api.rb +12 -0
  27. data/examples/http/twitter_stream_api.rb +26 -0
  28. data/examples/parsing/from_file.rb +14 -0
  29. data/examples/parsing/from_stdin.rb +9 -0
  30. data/examples/parsing/from_string.rb +13 -0
  31. data/ext/yajl/api/yajl_common.h +89 -0
  32. data/ext/yajl/api/yajl_gen.h +161 -0
  33. data/ext/yajl/api/yajl_parse.h +196 -0
  34. data/ext/yajl/api/yajl_version.h +23 -0
  35. data/ext/yajl/extconf.rb +7 -0
  36. data/ext/yajl/yajl.c +164 -0
  37. data/ext/yajl/yajl_alloc.c +65 -0
  38. data/ext/yajl/yajl_alloc.h +50 -0
  39. data/ext/yajl/yajl_buf.c +119 -0
  40. data/ext/yajl/yajl_buf.h +73 -0
  41. data/ext/yajl/yajl_bytestack.h +85 -0
  42. data/ext/yajl/yajl_encode.c +201 -0
  43. data/ext/yajl/yajl_encode.h +52 -0
  44. data/ext/yajl/yajl_ext.c +905 -0
  45. data/ext/yajl/yajl_ext.h +135 -0
  46. data/ext/yajl/yajl_gen.c +344 -0
  47. data/ext/yajl/yajl_lex.c +748 -0
  48. data/ext/yajl/yajl_lex.h +135 -0
  49. data/ext/yajl/yajl_parser.c +450 -0
  50. data/ext/yajl/yajl_parser.h +82 -0
  51. data/ext/yajl/yajl_version.c +7 -0
  52. data/lib/yajl.rb +75 -0
  53. data/lib/yajl/1.8/yajl.so +0 -0
  54. data/lib/yajl/1.9/yajl.so +0 -0
  55. data/lib/yajl/bzip2.rb +11 -0
  56. data/lib/yajl/bzip2/stream_reader.rb +31 -0
  57. data/lib/yajl/bzip2/stream_writer.rb +14 -0
  58. data/lib/yajl/deflate.rb +6 -0
  59. data/lib/yajl/deflate/stream_reader.rb +43 -0
  60. data/lib/yajl/deflate/stream_writer.rb +20 -0
  61. data/lib/yajl/gzip.rb +6 -0
  62. data/lib/yajl/gzip/stream_reader.rb +30 -0
  63. data/lib/yajl/gzip/stream_writer.rb +13 -0
  64. data/lib/yajl/http_stream.rb +212 -0
  65. data/lib/yajl/json_gem.rb +15 -0
  66. data/lib/yajl/json_gem/encoding.rb +51 -0
  67. data/lib/yajl/json_gem/parsing.rb +26 -0
  68. data/lib/yajl/version.rb +3 -0
  69. data/lib/yajl/yajl.rb +2 -0
  70. data/spec/encoding/encoding_spec.rb +271 -0
  71. data/spec/global/global_spec.rb +54 -0
  72. data/spec/http/fixtures/http.bzip2.dump +0 -0
  73. data/spec/http/fixtures/http.chunked.dump +11 -0
  74. data/spec/http/fixtures/http.deflate.dump +0 -0
  75. data/spec/http/fixtures/http.error.dump +12 -0
  76. data/spec/http/fixtures/http.gzip.dump +0 -0
  77. data/spec/http/fixtures/http.html.dump +1220 -0
  78. data/spec/http/fixtures/http.raw.dump +1226 -0
  79. data/spec/http/http_delete_spec.rb +98 -0
  80. data/spec/http/http_error_spec.rb +32 -0
  81. data/spec/http/http_get_spec.rb +109 -0
  82. data/spec/http/http_post_spec.rb +123 -0
  83. data/spec/http/http_put_spec.rb +105 -0
  84. data/spec/http/http_stream_options_spec.rb +27 -0
  85. data/spec/json_gem_compatibility/compatibility_spec.rb +203 -0
  86. data/spec/parsing/active_support_spec.rb +64 -0
  87. data/spec/parsing/chunked_spec.rb +96 -0
  88. data/spec/parsing/fixtures/fail.15.json +1 -0
  89. data/spec/parsing/fixtures/fail.16.json +1 -0
  90. data/spec/parsing/fixtures/fail.17.json +1 -0
  91. data/spec/parsing/fixtures/fail.26.json +1 -0
  92. data/spec/parsing/fixtures/fail11.json +1 -0
  93. data/spec/parsing/fixtures/fail12.json +1 -0
  94. data/spec/parsing/fixtures/fail13.json +1 -0
  95. data/spec/parsing/fixtures/fail14.json +1 -0
  96. data/spec/parsing/fixtures/fail19.json +1 -0
  97. data/spec/parsing/fixtures/fail20.json +1 -0
  98. data/spec/parsing/fixtures/fail21.json +1 -0
  99. data/spec/parsing/fixtures/fail22.json +1 -0
  100. data/spec/parsing/fixtures/fail23.json +1 -0
  101. data/spec/parsing/fixtures/fail24.json +1 -0
  102. data/spec/parsing/fixtures/fail25.json +1 -0
  103. data/spec/parsing/fixtures/fail27.json +2 -0
  104. data/spec/parsing/fixtures/fail28.json +2 -0
  105. data/spec/parsing/fixtures/fail3.json +1 -0
  106. data/spec/parsing/fixtures/fail4.json +1 -0
  107. data/spec/parsing/fixtures/fail5.json +1 -0
  108. data/spec/parsing/fixtures/fail6.json +1 -0
  109. data/spec/parsing/fixtures/fail9.json +1 -0
  110. data/spec/parsing/fixtures/pass.array.json +6 -0
  111. data/spec/parsing/fixtures/pass.codepoints_from_unicode_org.json +1 -0
  112. data/spec/parsing/fixtures/pass.contacts.json +1 -0
  113. data/spec/parsing/fixtures/pass.db100.xml.json +1 -0
  114. data/spec/parsing/fixtures/pass.db1000.xml.json +1 -0
  115. data/spec/parsing/fixtures/pass.dc_simple_with_comments.json +11 -0
  116. data/spec/parsing/fixtures/pass.deep_arrays.json +1 -0
  117. data/spec/parsing/fixtures/pass.difficult_json_c_test_case.json +1 -0
  118. data/spec/parsing/fixtures/pass.difficult_json_c_test_case_with_comments.json +1 -0
  119. data/spec/parsing/fixtures/pass.doubles.json +1 -0
  120. data/spec/parsing/fixtures/pass.empty_array.json +1 -0
  121. data/spec/parsing/fixtures/pass.empty_string.json +1 -0
  122. data/spec/parsing/fixtures/pass.escaped_bulgarian.json +4 -0
  123. data/spec/parsing/fixtures/pass.escaped_foobar.json +1 -0
  124. data/spec/parsing/fixtures/pass.item.json +1 -0
  125. data/spec/parsing/fixtures/pass.json-org-sample1.json +23 -0
  126. data/spec/parsing/fixtures/pass.json-org-sample2.json +11 -0
  127. data/spec/parsing/fixtures/pass.json-org-sample3.json +26 -0
  128. data/spec/parsing/fixtures/pass.json-org-sample4-nows.json +88 -0
  129. data/spec/parsing/fixtures/pass.json-org-sample4.json +89 -0
  130. data/spec/parsing/fixtures/pass.json-org-sample5.json +27 -0
  131. data/spec/parsing/fixtures/pass.map-spain.xml.json +1 -0
  132. data/spec/parsing/fixtures/pass.ns-invoice100.xml.json +1 -0
  133. data/spec/parsing/fixtures/pass.ns-soap.xml.json +1 -0
  134. data/spec/parsing/fixtures/pass.numbers-fp-4k.json +6 -0
  135. data/spec/parsing/fixtures/pass.numbers-fp-64k.json +61 -0
  136. data/spec/parsing/fixtures/pass.numbers-int-4k.json +11 -0
  137. data/spec/parsing/fixtures/pass.numbers-int-64k.json +154 -0
  138. data/spec/parsing/fixtures/pass.twitter-search.json +1 -0
  139. data/spec/parsing/fixtures/pass.twitter-search2.json +1 -0
  140. data/spec/parsing/fixtures/pass.unicode.json +3315 -0
  141. data/spec/parsing/fixtures/pass.yelp.json +1 -0
  142. data/spec/parsing/fixtures/pass1.json +56 -0
  143. data/spec/parsing/fixtures/pass2.json +1 -0
  144. data/spec/parsing/fixtures/pass3.json +6 -0
  145. data/spec/parsing/fixtures_spec.rb +40 -0
  146. data/spec/parsing/one_off_spec.rb +85 -0
  147. data/spec/rcov.opts +3 -0
  148. data/spec/spec_helper.rb +16 -0
  149. data/tasks/compile.rake +35 -0
  150. data/tasks/rspec.rake +16 -0
  151. data/yajl-ruby.gemspec +24 -0
  152. metadata +335 -0
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ # Load custom tasks
2
+ Dir['tasks/*.rake'].sort.each { |f| load f }
@@ -0,0 +1,72 @@
1
+ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/..')
2
+ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
3
+
4
+ require 'rubygems'
5
+ require 'benchmark'
6
+ require 'yajl'
7
+ require 'stringio'
8
+ begin
9
+ require 'json'
10
+ rescue LoadError
11
+ end
12
+ begin
13
+ require 'psych'
14
+ rescue LoadError
15
+ end
16
+ begin
17
+ require 'active_support'
18
+ rescue LoadError
19
+ end
20
+
21
+ filename = ARGV[0] || 'benchmark/subjects/ohai.json'
22
+ hash = File.open(filename, 'rb') { |f| Yajl::Parser.new.parse(f.read) }
23
+
24
+ times = ARGV[1] ? ARGV[1].to_i : 1000
25
+ puts "Starting benchmark encoding #{filename} #{times} times\n\n"
26
+ Benchmark.bmbm { |x|
27
+ io_encoder = Yajl::Encoder.new
28
+ string_encoder = Yajl::Encoder.new
29
+
30
+ x.report("Yajl::Encoder#encode (to an IO)") {
31
+ times.times {
32
+ io_encoder.encode(hash, StringIO.new)
33
+ }
34
+ }
35
+ x.report("Yajl::Encoder#encode (to a String)") {
36
+ times.times {
37
+ output = string_encoder.encode(hash)
38
+ }
39
+ }
40
+ if defined?(JSON)
41
+ x.report("JSON.generate") {
42
+ times.times {
43
+ JSON.generate(hash)
44
+ }
45
+ }
46
+ end
47
+ if defined?(Psych)
48
+ x.report("Psych.to_json") {
49
+ times.times {
50
+ Psych.to_json(hash)
51
+ }
52
+ }
53
+ if defined?(Psych::JSON::Stream)
54
+ x.report("Psych::JSON::Stream") {
55
+ times.times {
56
+ io = StringIO.new
57
+ stream = Psych::JSON::Stream.new io
58
+ stream.start
59
+ stream.push hash
60
+ stream.finish
61
+ }
62
+ }
63
+ end
64
+ end
65
+ if defined?(ActiveSupport::JSON)
66
+ x.report("ActiveSupport::JSON.encode") {
67
+ times.times {
68
+ ActiveSupport::JSON.encode(hash)
69
+ }
70
+ }
71
+ end
72
+ }
@@ -0,0 +1,42 @@
1
+ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/..')
2
+ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
3
+
4
+ require 'rubygems'
5
+ require 'benchmark'
6
+ require 'yajl'
7
+ require 'stringio'
8
+ begin
9
+ require 'json'
10
+ rescue LoadError
11
+ end
12
+
13
+ times = ARGV[0] ? ARGV[0].to_i : 1000
14
+ filename = 'benchmark/subjects/ohai.json'
15
+ json = File.new(filename, 'r')
16
+ hash = Yajl::Parser.new.parse(json)
17
+ json.close
18
+
19
+ puts "Starting benchmark encoding #{filename} #{times} times\n\n"
20
+ Benchmark.bmbm { |x|
21
+ encoder = Yajl::Encoder.new
22
+ x.report {
23
+ puts "Yajl::Encoder#encode"
24
+ times.times {
25
+ encoder.encode(hash, StringIO.new)
26
+ }
27
+ }
28
+ if defined?(JSON)
29
+ x.report {
30
+ puts "JSON's #to_json"
31
+ times.times {
32
+ JSON.generate(hash)
33
+ }
34
+ }
35
+ end
36
+ x.report {
37
+ puts "Marshal.dump"
38
+ times.times {
39
+ Marshal.dump(hash)
40
+ }
41
+ }
42
+ }
@@ -0,0 +1,53 @@
1
+ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/..')
2
+ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
3
+
4
+ require 'rubygems'
5
+ require 'benchmark'
6
+ require 'yajl'
7
+ begin
8
+ require 'json'
9
+ rescue LoadError
10
+ end
11
+ require 'yaml'
12
+
13
+ # JSON Section
14
+ filename = 'benchmark/subjects/ohai.json'
15
+ json = File.new(filename, 'r')
16
+ hash = Yajl::Parser.new.parse(json)
17
+ json.close
18
+
19
+ times = ARGV[0] ? ARGV[0].to_i : 1000
20
+ puts "Starting benchmark encoding #{filename} into JSON #{times} times\n\n"
21
+ Benchmark.bmbm { |x|
22
+ encoder = Yajl::Encoder.new
23
+ x.report {
24
+ puts "Yajl::Encoder#encode"
25
+ times.times {
26
+ encoder.encode(hash, StringIO.new)
27
+ }
28
+ }
29
+ if defined?(JSON)
30
+ x.report {
31
+ puts "JSON's #to_json"
32
+ times.times {
33
+ JSON.generate(hash)
34
+ }
35
+ }
36
+ end
37
+ }
38
+
39
+ # YAML Section
40
+ filename = 'benchmark/subjects/ohai.yml'
41
+ yml = File.new(filename, 'r')
42
+ data = YAML.load_stream(yml)
43
+ yml.close
44
+
45
+ puts "Starting benchmark encoding #{filename} into YAML #{times} times\n\n"
46
+ Benchmark.bmbm { |x|
47
+ x.report {
48
+ puts "YAML.dump"
49
+ times.times {
50
+ YAML.dump(data, StringIO.new)
51
+ }
52
+ }
53
+ }
data/benchmark/http.rb ADDED
@@ -0,0 +1,32 @@
1
+ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/..')
2
+ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
3
+
4
+ require 'rubygems'
5
+ require 'benchmark'
6
+ require 'yajl/http_stream'
7
+ require 'yajl/gzip'
8
+ require 'yajl/deflate'
9
+ require 'yajl/bzip2' unless defined?(Bzip2)
10
+ require 'json'
11
+ require 'uri'
12
+ require 'net/http'
13
+
14
+ uri = URI.parse('http://search.twitter.com/search.json?q=github')
15
+ # uri = URI.parse('http://localhost/yajl-ruby.git/benchmark/subjects/contacts.json')
16
+
17
+ times = ARGV[0] ? ARGV[0].to_i : 1
18
+ puts "Starting benchmark parsing #{uri.to_s} #{times} times\n\n"
19
+ Benchmark.bmbm { |x|
20
+ x.report {
21
+ puts "Yajl::HttpStream.get"
22
+ times.times {
23
+ Yajl::HttpStream.get(uri)
24
+ }
25
+ }
26
+ x.report {
27
+ puts "JSON.parser"
28
+ times.times {
29
+ JSON.parse(Net::HTTP.get_response(uri).body, :max_nesting => false)
30
+ }
31
+ }
32
+ }
@@ -0,0 +1,94 @@
1
+ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/..')
2
+ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
3
+
4
+ require 'rubygems'
5
+ require 'benchmark'
6
+ require 'yaml'
7
+ require 'yajl'
8
+ begin
9
+ require 'json'
10
+ rescue LoadError
11
+ end
12
+ begin
13
+ require 'psych'
14
+ rescue LoadError
15
+ end
16
+ begin
17
+ require 'active_support'
18
+ rescue LoadError
19
+ end
20
+
21
+ filename = ARGV[0] || 'benchmark/subjects/item.json'
22
+ json = File.new(filename, 'r')
23
+
24
+ times = ARGV[1] ? ARGV[1].to_i : 10_000
25
+ puts "Starting benchmark parsing #{File.size(filename)} bytes of JSON data #{times} times\n\n"
26
+ Benchmark.bmbm { |x|
27
+ io_parser = Yajl::Parser.new
28
+ io_parser.on_parse_complete = lambda {|obj|} if times > 1
29
+ x.report {
30
+ puts "Yajl::Parser#parse (from an IO)"
31
+ times.times {
32
+ json.rewind
33
+ io_parser.parse(json)
34
+ }
35
+ }
36
+ string_parser = Yajl::Parser.new
37
+ string_parser.on_parse_complete = lambda {|obj|} if times > 1
38
+ x.report {
39
+ puts "Yajl::Parser#parse (from a String)"
40
+ times.times {
41
+ json.rewind
42
+ string_parser.parse(json.read)
43
+ }
44
+ }
45
+ if defined?(JSON)
46
+ x.report {
47
+ puts "JSON.parse"
48
+ times.times {
49
+ json.rewind
50
+ JSON.parse(json.read, :max_nesting => false)
51
+ }
52
+ }
53
+ end
54
+ if defined?(ActiveSupport::JSON)
55
+ x.report {
56
+ puts "ActiveSupport::JSON.decode"
57
+ times.times {
58
+ json.rewind
59
+ ActiveSupport::JSON.decode(json.read)
60
+ }
61
+ }
62
+ end
63
+ x.report {
64
+ puts "YAML.load (from an IO)"
65
+ times.times {
66
+ json.rewind
67
+ YAML.load(json)
68
+ }
69
+ }
70
+ x.report {
71
+ puts "YAML.load (from a String)"
72
+ times.times {
73
+ json.rewind
74
+ YAML.load(json.read)
75
+ }
76
+ }
77
+ if defined?(Psych)
78
+ x.report {
79
+ puts "Psych.load (from an IO)"
80
+ times.times {
81
+ json.rewind
82
+ Psych.load(json)
83
+ }
84
+ }
85
+ x.report {
86
+ puts "Psych.load (from a String)"
87
+ times.times {
88
+ json.rewind
89
+ Psych.load(json.read)
90
+ }
91
+ }
92
+ end
93
+ }
94
+ json.close
@@ -0,0 +1,50 @@
1
+ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/..')
2
+ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
3
+
4
+ require 'rubygems'
5
+ require 'benchmark'
6
+ require 'yajl'
7
+ begin
8
+ require 'json'
9
+ rescue LoadError
10
+ end
11
+
12
+ # JSON section
13
+ filename = 'benchmark/subjects/ohai.json'
14
+ marshal_filename = 'benchmark/subjects/ohai.marshal_dump'
15
+ json = File.new(filename, 'r')
16
+ marshal_file = File.new(marshal_filename, 'r')
17
+
18
+ hash = {}
19
+
20
+ times = ARGV[0] ? ARGV[0].to_i : 1000
21
+ puts "Starting benchmark parsing #{File.size(filename)} bytes of JSON data #{times} times\n\n"
22
+ Benchmark.bmbm { |x|
23
+ x.report {
24
+ puts "Yajl::Parser#parse"
25
+ yajl = Yajl::Parser.new
26
+ yajl.on_parse_complete = lambda {|obj|} if times > 1
27
+ times.times {
28
+ json.rewind
29
+ hash = yajl.parse(json)
30
+ }
31
+ }
32
+ if defined?(JSON)
33
+ x.report {
34
+ puts "JSON.parse"
35
+ times.times {
36
+ json.rewind
37
+ JSON.parse(json.read, :max_nesting => false)
38
+ }
39
+ }
40
+ end
41
+ x.report {
42
+ puts "Marshal.load"
43
+ times.times {
44
+ marshal_file.rewind
45
+ Marshal.load(marshal_file)
46
+ }
47
+ }
48
+ }
49
+ json.close
50
+ marshal_file.close
@@ -0,0 +1,55 @@
1
+ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/..')
2
+ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
3
+
4
+ require 'rubygems'
5
+ require 'benchmark'
6
+ require 'yajl'
7
+ begin
8
+ require 'json'
9
+ rescue LoadError
10
+ end
11
+ require 'yaml'
12
+
13
+ # JSON section
14
+ filename = 'benchmark/subjects/ohai.json'
15
+ json = File.new(filename, 'r')
16
+
17
+ times = ARGV[0] ? ARGV[0].to_i : 1000
18
+ puts "Starting benchmark parsing #{File.size(filename)} bytes of JSON data #{times} times\n\n"
19
+ Benchmark.bmbm { |x|
20
+ parser = Yajl::Parser.new
21
+ parser.on_parse_complete = lambda {|obj|} if times > 1
22
+ x.report {
23
+ puts "Yajl::Parser#parse"
24
+ times.times {
25
+ json.rewind
26
+ parser.parse(json)
27
+ }
28
+ }
29
+ if defined?(JSON)
30
+ x.report {
31
+ puts "JSON.parse"
32
+ times.times {
33
+ json.rewind
34
+ JSON.parse(json.read, :max_nesting => false)
35
+ }
36
+ }
37
+ end
38
+ }
39
+ json.close
40
+
41
+ # YAML section
42
+ filename = 'benchmark/subjects/ohai.yml'
43
+ yaml = File.new(filename, 'r')
44
+
45
+ puts "Starting benchmark parsing #{File.size(filename)} bytes of YAML data #{times} times\n\n"
46
+ Benchmark.bmbm { |x|
47
+ x.report {
48
+ puts "YAML.load_stream"
49
+ times.times {
50
+ yaml.rewind
51
+ YAML.load(yaml)
52
+ }
53
+ }
54
+ }
55
+ yaml.close
@@ -0,0 +1,54 @@
1
+ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/..')
2
+ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
3
+
4
+ require 'rubygems'
5
+ require 'benchmark'
6
+ require 'yajl'
7
+ begin
8
+ require 'json'
9
+ rescue LoadError
10
+ end
11
+ begin
12
+ require 'active_support'
13
+ rescue LoadError
14
+ end
15
+
16
+ filename = 'benchmark/subjects/twitter_stream.json'
17
+ json = File.new(filename, 'r')
18
+
19
+ times = ARGV[0] ? ARGV[0].to_i : 100
20
+ puts "Starting benchmark parsing JSON stream (#{File.size(filename)} bytes of JSON data with 430 JSON separate strings) #{times} times\n\n"
21
+ Benchmark.bmbm { |x|
22
+ parser = Yajl::Parser.new
23
+ parser.on_parse_complete = lambda {|obj|}
24
+ x.report {
25
+ puts "Yajl::Parser#parse"
26
+ times.times {
27
+ json.rewind
28
+ parser.parse(json)
29
+ }
30
+ }
31
+ if defined?(JSON)
32
+ x.report {
33
+ puts "JSON.parse"
34
+ times.times {
35
+ json.rewind
36
+ while chunk = json.gets
37
+ JSON.parse(chunk, :max_nesting => false)
38
+ end
39
+ }
40
+ }
41
+ end
42
+ if defined?(ActiveSupport::JSON)
43
+ x.report {
44
+ puts "ActiveSupport::JSON.decode"
45
+ times.times {
46
+ json.rewind
47
+ while chunk = json.gets
48
+ ActiveSupport::JSON.decode(chunk)
49
+ end
50
+ }
51
+ }
52
+ end
53
+ }
54
+ json.close