Sha256: fcb8f208c30e1b617be20cdcc06730d86c7040c92345dd84e08bf98daa9a1da5

Contents?: true

Size: 1.1 KB

Versions: 76

Compression:

Stored size: 1.1 KB

Contents

$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/..')
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')

require 'rubygems'
require 'benchmark'
require 'yajl'
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

76 entries across 76 versions & 10 rubygems

Version Path
ffi-yajl-0.0.4-universal-java lib/ffi_yajl/benchmark/encode_json_and_yaml.rb
ffi-yajl-0.0.3-universal-java lib/ffi_yajl/benchmark/encode_json_and_yaml.rb
ffi-yajl-0.0.3 lib/ffi_yajl/benchmark/encode_json_and_yaml.rb
ffi-yajl-0.0.2-universal-java lib/ffi_yajl/benchmark/encode_json_and_yaml.rb
ffi-yajl-0.0.2 lib/ffi_yajl/benchmark/encode_json_and_yaml.rb
ffi-yajl-0.0.1-universal-java lib/ffi_yajl/benchmark/encode_json_and_yaml.rb
ffi-yajl-0.0.1 lib/ffi_yajl/benchmark/encode_json_and_yaml.rb
yajl-ruby-1.2.0 benchmark/encode_json_and_yaml.rb
yajl-ruby-zenjoy-1.1.0 benchmark/encode_json_and_yaml.rb
yajl-ruby-maglev--1.1.0 benchmark/encode_json_and_yaml.rb
yajl-ruby-1.1.0-x86-mswin32-60 benchmark/encode_json_and_yaml.rb
yajl-ruby-1.1.0-x86-mingw32 benchmark/encode_json_and_yaml.rb
yajl-ruby-1.1.0 benchmark/encode_json_and_yaml.rb
yajl-ruby-1.0.0-x86-mswin32-60 benchmark/encode_json_and_yaml.rb
yajl-ruby-1.0.0-x86-mingw32 benchmark/encode_json_and_yaml.rb
yajl-ruby-1.0.0 benchmark/encode_json_and_yaml.rb