Sha256: e2637de61877580ff6bc4cc04eb127d149b856c6109e2bcf3ade4af0078b229a

Contents?: true

Size: 779 Bytes

Versions: 2

Compression:

Stored size: 779 Bytes

Contents

# encoding: UTF-8
require 'rubygems'
require 'benchmark'
require 'yajl'
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.5 benchmark/parse_json_and_marshal.rb
brianmario-yajl-ruby-0.4.6 benchmark/parse_json_and_marshal.rb