Sha256: dbbfaebdda81cfc3e2b7d78cdc802c0b264170494489eb3cc8c427044ac48b7a

Contents?: true

Size: 958 Bytes

Versions: 2

Compression:

Stored size: 958 Bytes

Contents

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

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

# warm up the filesystem
json.read
json.rewind
marshal_file.read
marshal_file.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::Parser#parse"
    times.times {
      json.rewind
      hash = Yajl::Parser.new.parse(json)
    }
  }
  x.report {
    puts "JSON.parse"
    times.times {
      json.rewind
      JSON.parse(json.read, :max_nesting => false)
    }
  }
  x.report {
    puts "Marshal.load"
    times.times {
      marshal_file.rewind
      Marshal.load(marshal_file)
    }
  }
}
json.close
marshal_file.close

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
brianmario-yajl-ruby-0.5.5 benchmark/parse_json_and_marshal.rb
yajl-ruby-0.5.5 benchmark/parse_json_and_marshal.rb