Sha256: 5eb3e53d65501d0029aa56557a2b8de860f50c8a57d0a3bc2222e44e948ee814

Contents?: true

Size: 682 Bytes

Versions: 24

Compression:

Stored size: 682 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/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.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

24 entries across 24 versions & 5 rubygems

Version Path
brianmario-yajl-ruby-0.5.10 benchmark/encode_json_and_marshal.rb
brianmario-yajl-ruby-0.5.11 benchmark/encode_json_and_marshal.rb
brianmario-yajl-ruby-0.5.12 benchmark/encode_json_and_marshal.rb
brianmario-yajl-ruby-0.5.6 benchmark/encode_json_and_marshal.rb
brianmario-yajl-ruby-0.5.7 benchmark/encode_json_and_marshal.rb
brianmario-yajl-ruby-0.5.8 benchmark/encode_json_and_marshal.rb
brianmario-yajl-ruby-0.5.9 benchmark/encode_json_and_marshal.rb
brianmario-yajl-ruby-0.6.0 benchmark/encode_json_and_marshal.rb
brianmario-yajl-ruby-0.6.1 benchmark/encode_json_and_marshal.rb
brianmario-yajl-ruby-0.6.3 benchmark/encode_json_and_marshal.rb
jdg-yajl-ruby-0.5.12 benchmark/encode_json_and_marshal.rb
oortle-yajl-ruby-0.5.8 benchmark/encode_json_and_marshal.rb
filipegiusti-yajl-ruby-0.6.4 benchmark/encode_json_and_marshal.rb
yajl-ruby-0.6.3 benchmark/encode_json_and_marshal.rb
yajl-ruby-0.6.2 benchmark/encode_json_and_marshal.rb
yajl-ruby-0.6.0 benchmark/encode_json_and_marshal.rb
yajl-ruby-0.6.1 benchmark/encode_json_and_marshal.rb
yajl-ruby-0.5.6 benchmark/encode_json_and_marshal.rb
yajl-ruby-0.5.7 benchmark/encode_json_and_marshal.rb
yajl-ruby-0.5.8 benchmark/encode_json_and_marshal.rb