Sha256: 4fc6e02f5616f1308643d66f1527ec50274df522bf968f6bcce5da234bc856eb

Contents?: true

Size: 686 Bytes

Versions: 2

Compression:

Stored size: 686 Bytes

Contents

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

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

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

2 entries across 2 versions & 2 rubygems

Version Path
brianmario-yajl-ruby-0.5.5 benchmark/encode_json_and_marshal.rb
yajl-ruby-0.5.5 benchmark/encode_json_and_marshal.rb