Sha256: bfbaa70230aef26b521390a6214c988a8954c30075de993fed6cad604e6cddce

Contents?: true

Size: 1.19 KB

Versions: 9

Compression:

Stored size: 1.19 KB

Contents

$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + "/..")
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + "/../lib")

require "rubygems" unless defined?(Gem)
require "benchmark" unless defined?(Benchmark)
require "yajl"
begin
  require "json" unless defined?(JSON)
rescue LoadError
end

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

hash = {}

times = ARGV[0] ? ARGV[0].to_i : 1000
puts "Starting benchmark parsing #{File.size(filename)} bytes of JSON data #{times} times\n\n"
Benchmark.bmbm do |x|
  x.report do
    puts "Yajl::Parser#parse"
    yajl = Yajl::Parser.new
    yajl.on_parse_complete = ->(obj) {} if times > 1
    times.times do
      json.rewind
      hash = yajl.parse(json)
    end
  end
  if defined?(JSON)
    x.report do
      puts "JSON.parse"
      times.times do
        json.rewind
        JSON.parse(json.read, max_nesting: false)
      end
    end
  end
  x.report do
    puts "Marshal.load"
    times.times do
      marshal_file.rewind
      Marshal.load(marshal_file)
    end
  end
end
json.close
marshal_file.close

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
ffi-yajl-2.6.0-universal-java lib/ffi_yajl/benchmark/parse_json_and_marshal.rb
ffi-yajl-2.6.0 lib/ffi_yajl/benchmark/parse_json_and_marshal.rb
ffi-yajl-3.0.0-universal-java lib/ffi_yajl/benchmark/parse_json_and_marshal.rb
ffi-yajl-3.0.0 lib/ffi_yajl/benchmark/parse_json_and_marshal.rb
ffi-yajl-2.5.0-universal-java lib/ffi_yajl/benchmark/parse_json_and_marshal.rb
ffi-yajl-2.4.0-universal-java lib/ffi_yajl/benchmark/parse_json_and_marshal.rb
ffi-yajl-2.4.0 lib/ffi_yajl/benchmark/parse_json_and_marshal.rb
ffi-yajl-2.3.4 lib/ffi_yajl/benchmark/parse_json_and_marshal.rb
ffi-yajl-2.3.4-universal-java lib/ffi_yajl/benchmark/parse_json_and_marshal.rb