blob: 955f22f4a3d18c889518b8158678b05824dea6c0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/..')
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
require 'rubygems'
require 'benchmark'
require 'yajl'
begin
require 'json'
rescue LoadError
end
begin
require 'active_support'
rescue LoadError
end
filename = 'benchmark/subjects/twitter_stream.json'
json = File.new(filename, 'r')
times = ARGV[0] ? ARGV[0].to_i : 100
puts "Starting benchmark parsing JSON stream (#{File.size(filename)} bytes of JSON data with 430 JSON separate strings) #{times} times\n\n"
Benchmark.bmbm { |x|
parser = Yajl::Parser.new
parser.on_parse_complete = lambda { |obj| }
x.report {
puts "Yajl::Parser#parse"
times.times {
json.rewind
parser.parse(json)
}
}
if defined?(JSON)
x.report {
puts "JSON.parse"
times.times {
json.rewind
while chunk = json.gets
JSON.parse(chunk, :max_nesting => false)
end
}
}
end
if defined?(ActiveSupport::JSON)
x.report {
puts "ActiveSupport::JSON.decode"
times.times {
json.rewind
while chunk = json.gets
ActiveSupport::JSON.decode(chunk)
end
}
}
end
}
json.close
|