Sha256: 3a3ab8fa22a2f7b99bcb5827bf3da10c9abbcba93c81a5b63cafd938f1893cc8

Contents?: true

Size: 894 Bytes

Versions: 8

Compression:

Stored size: 894 Bytes

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'
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 do |x|
  encoder = Yajl::Encoder.new
  x.report do
    puts "Yajl::Encoder#encode"
    times.times do
      encoder.encode(hash, StringIO.new)
    end
  end
  if defined?(JSON)
    x.report do
      puts "JSON's #to_json"
      times.times do
        JSON.generate(hash)
      end
    end
  end
  x.report do
    puts "Marshal.dump"
    times.times do
      Marshal.dump(hash)
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
ffi-yajl-2.3.0-universal-java lib/ffi_yajl/benchmark/encode_json_and_marshal.rb
ffi-yajl-2.3.0 lib/ffi_yajl/benchmark/encode_json_and_marshal.rb
ffi-yajl-2.2.3-universal-java lib/ffi_yajl/benchmark/encode_json_and_marshal.rb
ffi-yajl-2.2.3 lib/ffi_yajl/benchmark/encode_json_and_marshal.rb
ffi-yajl-2.2.2 lib/ffi_yajl/benchmark/encode_json_and_marshal.rb
ffi-yajl-2.2.2-universal-java lib/ffi_yajl/benchmark/encode_json_and_marshal.rb
ffi-yajl-2.2.1 lib/ffi_yajl/benchmark/encode_json_and_marshal.rb
ffi-yajl-2.2.1-universal-java lib/ffi_yajl/benchmark/encode_json_and_marshal.rb