blob: fe579a93a7ec255940aed4fad40028e4f7ce311f (
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
55
|
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + "/..")
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + "/../lib")
require "rubygems" unless defined?(Gem)
require "benchmark" unless defined?(Benchmark)
require "yajl"
begin
require "json" unless defined?(JSON)
rescue LoadError
end
require "yaml" unless defined?(YAML)
# JSON section
filename = "benchmark/subjects/ohai.json"
json = File.new(filename, "r")
times = ARGV[0] ? ARGV[0].to_i : 1000
puts "Starting benchmark parsing #{File.size(filename)} bytes of JSON data #{times} times\n\n"
Benchmark.bmbm do |x|
parser = Yajl::Parser.new
parser.on_parse_complete = ->(obj) {} if times > 1
x.report do
puts "Yajl::Parser#parse"
times.times do
json.rewind
parser.parse(json)
end
end
if defined?(JSON)
x.report do
puts "JSON.parse"
times.times do
json.rewind
JSON.parse(json.read, max_nesting: false)
end
end
end
end
json.close
# YAML section
filename = "benchmark/subjects/ohai.yml"
yaml = File.new(filename, "r")
puts "Starting benchmark parsing #{File.size(filename)} bytes of YAML data #{times} times\n\n"
Benchmark.bmbm do |x|
x.report do
puts "YAML.load_stream"
times.times do
yaml.rewind
YAML.load(yaml)
end
end
end
yaml.close
|