Sha256: 41f7e27504b658ff3d791e45dc83d2d369f104121a6d38d697f1af1c7962014f

Contents?: true

Size: 823 Bytes

Versions: 4

Compression:

Stored size: 823 Bytes

Contents

# encoding: UTF-8
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/..')

require 'rubygems'
require 'benchmark'
require 'yajl_ext'
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

4 entries across 4 versions & 2 rubygems

Version Path
yajl-ruby-0.7.8 benchmark/encode_json_and_marshal.rb
yajl-ruby-0.7.7 benchmark/encode_json_and_marshal.rb
benofsky-yajl-ruby-0.7.7 benchmark/encode_json_and_marshal.rb
benofsky-yajl-ruby-0.7.6 benchmark/encode_json_and_marshal.rb