Sha256: ffd5c1433ea6419768c7867d87bb0399fefad641f24d53796ac917ac4b154f12
Contents?: true
Size: 842 Bytes
Versions: 2
Compression:
Stored size: 842 Bytes
Contents
# encoding: UTF-8 require 'rubygems' require 'benchmark' require 'yajl' require 'json' # Can't use ActiveSuport::JSON.encode with the JSON gem loaded # require 'activesupport' filename = ARGV[0] || 'benchmark/subjects/contacts.json' json = File.new(filename, 'r') hash = Yajl::Stream.parse(json) json.close times = ARGV[1] ? ARGV[1].to_i : 1 puts "Starting benchmark encoding #{filename} #{times} times\n\n" Benchmark.bm { |x| x.report { puts "Yajl::Stream.encode" times.times { Yajl::Stream.encode(hash, StringIO.new) } } x.report { puts "JSON's #to_json" times.times { JSON.generate(hash) } } # Can't use ActiveSuport::JSON.encode with the JSON gem loaded # # x.report { # puts "ActiveSupport::JSON.encode" # times.times { # ActiveSupport::JSON.encode(hash) # } # } }
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
brianmario-yajl-ruby-0.4.5 | benchmark/encode.rb |
brianmario-yajl-ruby-0.4.6 | benchmark/encode.rb |