Sha256: 2efcbe7f8bb81b5ac264b8528f38f3024e09838260020e1bb7aceb9c4901778c

Contents?: true

Size: 974 Bytes

Versions: 22

Compression:

Stored size: 974 Bytes

Contents

# encoding: UTF-8
require 'rubygems'
require 'benchmark'
require 'yajl_ext'
require 'json'
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 : 1
puts "Starting benchmark encoding #{filename} into JSON #{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)
    }
  }
}

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

times = ARGV[0] ? ARGV[0].to_i : 1
puts "Starting benchmark encoding #{filename} into YAML #{times} times\n\n"
Benchmark.bm { |x|
  x.report {
    puts "YAML.dump"
    times.times {
      YAML.dump(data, StringIO.new)
    }
  }
}

Version data entries

22 entries across 22 versions & 4 rubygems

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