Sha256: 3338a767c3dd302195a90a61e2c8c8dfe9137878b7dc499b3168becad3f9788e

Contents?: true

Size: 1009 Bytes

Versions: 11

Compression:

Stored size: 1009 Bytes

Contents

# encoding: UTF-8
require 'rubygems'
require 'benchmark'
require 'yajl_ext'
begin
  require 'json'
rescue LoadError
end
require 'yaml'

# JSON Section
filename = 'benchmark/subjects/ohai.json'
json = File.new(filename, 'r')
hash = Yajl::Parser.new.parse(json)
json.close

times = ARGV[0] ? ARGV[0].to_i : 1000
puts "Starting benchmark encoding #{filename} into JSON #{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
}

# YAML Section
filename = 'benchmark/subjects/ohai.yml'
yml = File.new(filename, 'r')
data = YAML.load_stream(yml)
yml.close

puts "Starting benchmark encoding #{filename} into YAML #{times} times\n\n"
Benchmark.bmbm { |x|
  x.report {
    puts "YAML.dump"
    times.times {
      YAML.dump(data, StringIO.new)
    }
  }
}

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
yajl-ruby-0.7.6 benchmark/encode_json_and_yaml.rb
yajl-ruby-0.7.5 benchmark/encode_json_and_yaml.rb
yajl-ruby-0.7.4 benchmark/encode_json_and_yaml.rb
yajl-ruby-0.7.3 benchmark/encode_json_and_yaml.rb
yajl-ruby-0.7.2 benchmark/encode_json_and_yaml.rb
yajl-ruby-0.7.1 benchmark/encode_json_and_yaml.rb
yajl-ruby-0.7.0 benchmark/encode_json_and_yaml.rb
yajl-ruby-0.6.9 benchmark/encode_json_and_yaml.rb
yajl-ruby-0.6.8 benchmark/encode_json_and_yaml.rb
yajl-ruby-0.6.7 benchmark/encode_json_and_yaml.rb
yajl-ruby-0.6.6 benchmark/encode_json_and_yaml.rb