Sha256: a0829a55a1d95c968b1675996f188d59d07e81d7b0999418028896b7be5fbf2d

Contents?: true

Size: 1.07 KB

Versions: 7

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/contacts.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

7 entries across 7 versions & 2 rubygems

Version Path
brianmario-yajl-ruby-0.5.0 benchmark/parse_json_and_yaml.rb
brianmario-yajl-ruby-0.5.1 benchmark/parse_json_and_yaml.rb
brianmario-yajl-ruby-0.5.2 benchmark/parse_json_and_yaml.rb
brianmario-yajl-ruby-0.5.3 benchmark/parse_json_and_yaml.rb
brianmario-yajl-ruby-0.5.4 benchmark/parse_json_and_yaml.rb
brianmario-yajl-ruby-0.5.5 benchmark/parse_json_and_yaml.rb
yajl-ruby-0.5.5 benchmark/parse_json_and_yaml.rb