Sha256: ef7260c65812255f08582f2cc97adeaacfb0e588fb3fbd3830ff799ce893ab3f

Contents?: true

Size: 891 Bytes

Versions: 5

Compression:

Stored size: 891 Bytes

Contents

# encoding: UTF-8
$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'
require 'stringio'
begin
  require 'json'
rescue LoadError
end

times = ARGV[0] ? ARGV[0].to_i : 1000
filename = 'benchmark/subjects/ohai.json'
json = File.new(filename, 'r')
hash = Yajl::Parser.new.parse(json)
json.close

puts "Starting benchmark encoding #{filename} #{times} times\n\n"
Benchmark.bmbm { |x|
  encoder = Yajl::Encoder.new
  x.report {
    puts "Yajl::Encoder#encode"
    times.times {
      encoder.encode(hash, StringIO.new)
    }
  }
  if defined?(JSON)
    x.report {
      puts "JSON's #to_json"
      times.times {
        JSON.generate(hash)
      }
    }
  end
  x.report {
    puts "Marshal.dump"
    times.times {
      Marshal.dump(hash)
    }
  }
}

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
yajl-ruby-0.8.3 benchmark/encode_json_and_marshal.rb
yajl-ruby-0.8.2 benchmark/encode_json_and_marshal.rb
yajl-ruby-0.8.1 benchmark/encode_json_and_marshal.rb
yajl-ruby-0.8.0 benchmark/encode_json_and_marshal.rb
yajl-ruby-0.7.9 benchmark/encode_json_and_marshal.rb