Sha256: b56cc2f7ba3b20cb95a4af288b740cd234eababb67b017e445da6657542a0d2a

Contents?: true

Size: 1.1 KB

Versions: 76

Compression:

Stored size: 1.1 KB

Contents

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

require 'rubygems'
require 'benchmark'
require 'yajl'
begin
  require '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 { |x|
  x.report {
    puts "Yajl::Parser#parse"
    yajl = Yajl::Parser.new
    yajl.on_parse_complete = lambda {|obj|} if times > 1
    times.times {
      json.rewind
      hash = yajl.parse(json)
    }
  }
  if defined?(JSON)
    x.report {
      puts "JSON.parse"
      times.times {
        json.rewind
        JSON.parse(json.read, :max_nesting => false)
      }
    }
  end
  x.report {
    puts "Marshal.load"
    times.times {
      marshal_file.rewind
      Marshal.load(marshal_file)
    }
  }
}
json.close
marshal_file.close

Version data entries

76 entries across 76 versions & 10 rubygems

Version Path
ffi-yajl-0.2.0 lib/ffi_yajl/benchmark/parse_json_and_marshal.rb
ffi-yajl-0.2.0-universal-java lib/ffi_yajl/benchmark/parse_json_and_marshal.rb
ffi-yajl-0.1.7 lib/ffi_yajl/benchmark/parse_json_and_marshal.rb
ffi-yajl-0.1.7-universal-java lib/ffi_yajl/benchmark/parse_json_and_marshal.rb
yajl-ruby-1.2.1 benchmark/parse_json_and_marshal.rb
ffi-yajl-0.1.6 lib/ffi_yajl/benchmark/parse_json_and_marshal.rb
ffi-yajl-0.1.6-universal-java lib/ffi_yajl/benchmark/parse_json_and_marshal.rb
ffi-yajl-0.1.5-universal-java lib/ffi_yajl/benchmark/parse_json_and_marshal.rb
ffi-yajl-0.1.5 lib/ffi_yajl/benchmark/parse_json_and_marshal.rb
ffi-yajl-0.1.4-universal-java lib/ffi_yajl/benchmark/parse_json_and_marshal.rb
ffi-yajl-0.1.4 lib/ffi_yajl/benchmark/parse_json_and_marshal.rb
ffi-yajl-0.1.3 lib/ffi_yajl/benchmark/parse_json_and_marshal.rb
ffi-yajl-0.1.3-universal-java lib/ffi_yajl/benchmark/parse_json_and_marshal.rb
ffi-yajl-0.1.2 lib/ffi_yajl/benchmark/parse_json_and_marshal.rb
ffi-yajl-0.1.2-universal-java lib/ffi_yajl/benchmark/parse_json_and_marshal.rb
ffi-yajl-0.1.1 lib/ffi_yajl/benchmark/parse_json_and_marshal.rb
ffi-yajl-0.1.1-universal-java lib/ffi_yajl/benchmark/parse_json_and_marshal.rb
ffi-yajl-0.1.0-universal-java lib/ffi_yajl/benchmark/parse_json_and_marshal.rb
ffi-yajl-0.1.0 lib/ffi_yajl/benchmark/parse_json_and_marshal.rb
ffi-yajl-0.0.4 lib/ffi_yajl/benchmark/parse_json_and_marshal.rb