Sha256: b35007c6df1caf3da62eb2acc1949722a88ca79670bf502b5e53b6894891d938

Contents?: true

Size: 1.07 KB

Versions: 22

Compression:

Stored size: 1.07 KB

Contents

# encoding: UTF-8
require 'rubygems'
require 'benchmark'
require 'yajl_ext'
require 'json'
require 'yaml'

# JSON section
filename = 'benchmark/subjects/ohai.json'
json = File.new(filename, 'r')

# warm up the filesystem
json.read
json.rewind

times = ARGV[0] ? ARGV[0].to_i : 1
puts "Starting benchmark parsing #{File.size(filename)} bytes of JSON data #{times} times\n\n"
Benchmark.bm { |x|
  parser = Yajl::Parser.new
  x.report {
    puts "Yajl::Parser#parse"
    times.times {
      json.rewind
      parser.parse(json)
    }
  }
  x.report {
    puts "JSON.parse"
    times.times {
      json.rewind
      JSON.parse(json.read, :max_nesting => false)
    }
  }
}
json.close

# YAML section
filename = 'benchmark/subjects/contacts.yml'
yaml = File.new(filename, 'r')

# warm up the filesystem
yaml.read
yaml.rewind

times = ARGV[0] ? ARGV[0].to_i : 1
puts "Starting benchmark parsing #{File.size(filename)} bytes of YAML data #{times} times\n\n"
Benchmark.bm { |x|
  x.report {
    puts "YAML.load_stream"
    times.times {
      yaml.rewind
      YAML.load(yaml)
    }
  }
}
yaml.close

Version data entries

22 entries across 22 versions & 4 rubygems

Version Path
brianmario-yajl-ruby-0.5.10 benchmark/parse_json_and_yaml.rb
brianmario-yajl-ruby-0.5.11 benchmark/parse_json_and_yaml.rb
brianmario-yajl-ruby-0.5.12 benchmark/parse_json_and_yaml.rb
brianmario-yajl-ruby-0.5.6 benchmark/parse_json_and_yaml.rb
brianmario-yajl-ruby-0.5.7 benchmark/parse_json_and_yaml.rb
brianmario-yajl-ruby-0.5.8 benchmark/parse_json_and_yaml.rb
brianmario-yajl-ruby-0.5.9 benchmark/parse_json_and_yaml.rb
brianmario-yajl-ruby-0.6.0 benchmark/parse_json_and_yaml.rb
brianmario-yajl-ruby-0.6.1 benchmark/parse_json_and_yaml.rb
jdg-yajl-ruby-0.5.12 benchmark/parse_json_and_yaml.rb
oortle-yajl-ruby-0.5.8 benchmark/parse_json_and_yaml.rb
yajl-ruby-0.6.3 benchmark/parse_json_and_yaml.rb
yajl-ruby-0.6.2 benchmark/parse_json_and_yaml.rb
yajl-ruby-0.6.0 benchmark/parse_json_and_yaml.rb
yajl-ruby-0.6.1 benchmark/parse_json_and_yaml.rb
yajl-ruby-0.5.6 benchmark/parse_json_and_yaml.rb
yajl-ruby-0.5.7 benchmark/parse_json_and_yaml.rb
yajl-ruby-0.5.8 benchmark/parse_json_and_yaml.rb
yajl-ruby-0.5.9 benchmark/parse_json_and_yaml.rb
yajl-ruby-0.5.10 benchmark/parse_json_and_yaml.rb