Sha256: 66882c115a824573b215fc5f1c635df07afc9cb1c78229ddcd08bd59555e7998

Contents?: true

Size: 1.22 KB

Versions: 3

Compression:

Stored size: 1.22 KB

Contents

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

require 'gson'
require 'optparse'

options = {
  :times => 1_000,
  :file => File.expand_path(File.dirname(__FILE__) + '/subjects/ohai.json'),
  :type => :decode
}

OptionParser.new do |opts|
  opts.banner = "Usage: profile.rb [options]"
  opts.on("-t", "--type TYPE", [:decode, :encode], "Type of the operation (default: #{options[:type]}") do |v|
    options[:verbose] = v
  end
  opts.on("-n", "--times NUMBER", Integer, "Number of iterations (default: #{options[:times]})") do |v|
    options[:times] = v
  end
  opts.on("-f", "--file FILE", "File to use as JSON source (default: #{options[:file]})") do |v|
    options[:file] = v
  end
  opts.on_tail("-?", "--help", "Show this message") do
    puts opts
    exit
  end
end.parse!

json = File.read(options[:file])
hash = Gson::Decoder.new.decode(json)

case options[:type]
when :decode, "decode"
  decoder = Gson::Decoder.new
  options[:times].times do
    decoder.decode(json)
  end
when :encode, "encode"
  encoder = Gson::Encoder.new
  options[:times].times do
    encoder.encode(hash)
  end
else
  raise "Unknown type: #{options[:type].inspect}"
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
gson-0.6.1-java benchmark/profile.rb
gson-0.6.0-java benchmark/profile.rb
gson-0.5.0-java benchmark/profile.rb