Sha256: e6510c1f99344f909e6440c4e70bca7ccc2358238f2442cba918fcaa406d5b59

Contents?: true

Size: 873 Bytes

Versions: 76

Compression:

Stored size: 873 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 { |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

76 entries across 76 versions & 10 rubygems

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