Sha256: 1d19b7c451e66cb0ae276ea8e245a95d9b1520833583f9cacb61523d3120584d

Contents?: true

Size: 783 Bytes

Versions: 2

Compression:

Stored size: 783 Bytes

Contents

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

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

# warm up the filesystem
json.read
json.rewind

hash = {}

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|
  x.report {
    puts "Yajl::Stream.parse"
    times.times {
      json.rewind
      hash = Yajl::Stream.parse(json)
    }
  }
  x.report {
    puts "JSON.parser"
    times.times {
      json.rewind
      JSON.parse(json.read, :max_nesting => false)
    }
  }
  data = Marshal.dump(hash)
  x.report {
    puts "Marshal.load"
    times.times {
      Marshal.load(data)
    }
  }
}
json.close

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
brianmario-yajl-ruby-0.4.7 benchmark/parse_json_and_marshal.rb
brianmario-yajl-ruby-0.4.8 benchmark/parse_json_and_marshal.rb