Sha256: c9d1fb375d7e85a1c8fddc14fb3fdbf6589167879f843d8f75de7fdc12541d13

Contents?: true

Size: 697 Bytes

Versions: 3

Compression:

Stored size: 697 Bytes

Contents

# encoding: UTF-8
require 'rubygems'
require 'benchmark'
require 'yajl_ext'
require 'stringio'
require 'json'

filename = ARGV[0] || 'benchmark/subjects/contacts.json'
json = File.new(filename, 'r')
hash = Yajl::Parser.new.parse(json)
json.close

times = ARGV[1] ? ARGV[1].to_i : 1
puts "Starting benchmark encoding #{filename} #{times} times\n\n"
Benchmark.bm { |x|
  encoder = Yajl::Encoder.new
  x.report {
    puts "Yajl::Encoder#encode"
    times.times {
      encoder.encode(hash, StringIO.new)
    }
  }
  x.report {
    puts "JSON's #to_json"
    times.times {
      JSON.generate(hash)
    }
  }
  x.report {
    puts "Marshal.dump"
    times.times {
      Marshal.dump(hash)
    }
  }
}

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
brianmario-yajl-ruby-0.5.2 benchmark/encode_json_and_marshal.rb
brianmario-yajl-ruby-0.5.3 benchmark/encode_json_and_marshal.rb
brianmario-yajl-ruby-0.5.4 benchmark/encode_json_and_marshal.rb