Sha256: 5a135b6a40715fb54fe8b0e7d2849c2cd568ddc1896a8225261a32cd0e42307e

Contents?: true

Size: 942 Bytes

Versions: 2

Compression:

Stored size: 942 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 : 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)
    }
  }
  x.report {
    puts "JSON's #to_json"
    times.times {
      JSON.generate(hash)
    }
  }
}

# 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

2 entries across 2 versions & 1 rubygems

Version Path
yajl-ruby-0.6.5 benchmark/encode_json_and_yaml.rb
yajl-ruby-0.6.4 benchmark/encode_json_and_yaml.rb