Sha256: 6bfa54c0a4fe7cff83b5f333a88b7f867018339c4e4368eb7f36124a58d4fe09

Contents?: true

Size: 1.05 KB

Versions: 24

Compression:

Stored size: 1.05 KB

Contents

# encoding: UTF-8
require 'rubygems'
require 'benchmark'
require 'yajl_ext'
require 'stringio'
require 'json'
# Can't use ActiveSuport::JSON.encode with the JSON gem loaded
# require 'activesupport'

filename = ARGV[0] || 'benchmark/subjects/ohai.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|
  io_encoder = Yajl::Encoder.new
  x.report {
    puts "Yajl::Encoder#encode (to an IO)"
    times.times {
      io_encoder.encode(hash, StringIO.new)
    }
  }
  string_encoder = Yajl::Encoder.new
  x.report {
    puts "Yajl::Encoder#encode (to a String)"
    times.times {
      output = string_encoder.encode(hash)
    }
  }
  x.report {
    puts "JSON's #to_json"
    times.times {
      JSON.generate(hash)
    }
  }
  # Can't use ActiveSuport::JSON.encode with the JSON gem loaded
  #
  # x.report {
  #   puts "ActiveSupport::JSON.encode"
  #   times.times {
  #     ActiveSupport::JSON.encode(hash)
  #   }
  # }
}

Version data entries

24 entries across 24 versions & 5 rubygems

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