Sha256: 25932b85687e425cb5450cea217b0e1027241370b0ce73f05f0b26bd22ab3be4
Contents?: true
Size: 978 Bytes
Versions: 5
Compression:
Stored size: 978 Bytes
Contents
# encoding: UTF-8 require 'rubygems' require 'benchmark' require 'yajl_ext' require 'json' require 'yaml' # JSON Section filename = 'benchmark/subjects/contacts.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
5 entries across 5 versions & 2 rubygems