benchmarking/benchmark.rb in jrjackson-0.1.1 vs benchmarking/benchmark.rb in jrjackson-0.2.0

- old
+ new

@@ -1,8 +1,9 @@ #!/usr/bin/env ruby require 'rubygems' +require 'bigdecimal' require 'benchmark' require 'thread' require 'digest' require 'json/ext' require 'gson' @@ -60,85 +61,36 @@ org_array << randomize_entries(hsh) end generated_array = [] generated_smile = [] -q = Queue.new org_array.each do |hsh| generated_array << JrJackson::Raw.generate(hsh) end +q = Queue.new + Benchmark.bmbm("jackson parse symbol keys: ".size) do |x| x.report("json java parse:") do - th1 = Thread.new(generated_array) do |arry| - 50.times {arry.each {|string| ::JSON.parse("[#{string}]").first }} - q << true - end - th2 = Thread.new(generated_array) do |arry| - 50.times {arry.each {|string| ::JSON.parse("[#{string}]").first }} - q << true - end - q.pop - q.pop - # 50.times {generated_array.each {|string| ::JSON.parse("[#{string}]").first }} + 50.times {generated_array.each {|string| ::JSON.parse(string) }} end x.report("gson parse:") do - th1 = Thread.new(generated_array) do |arry| - 50.times {arry.each {|string| ::Gson::Decoder.new({}).decode(string) }} - q << true - end - th2 = Thread.new(generated_array) do |arry| - 50.times {arry.each {|string| ::Gson::Decoder.new({}).decode(string) }} - q << true - end - q.pop - q.pop - # 50.times {generated_array.each {|string| ::Gson::Decoder.new({}).decode(string) }} + 50.times {generated_array.each {|string| ::Gson::Decoder.new({}).decode(string) }} end - x.report("jackson parse raw:") do - th1 = Thread.new(generated_array) do |arry| - 50.times {arry.each {|string| JrJackson::Raw.parse(string) }} - q << true - end - th2 = Thread.new(generated_array) do |arry| - 50.times {arry.each {|string| JrJackson::Raw.parse(string) }} - q << true - end - q.pop - q.pop - # 50.times {generated_array.each {|string| JrJackson::Raw.parse(string) }} + x.report("jackson parse string keys:") do + 50.times {generated_array.each {|string| JrJackson::Raw.parse_str(string) }} end x.report("jackson parse symbol keys:") do - th1 = Thread.new(generated_array) do |arry| - 50.times {arry.each {|string| JrJackson::Sym.parse(string) }} - q << true - end - th2 = Thread.new(generated_array) do |arry| - 50.times {arry.each {|string| JrJackson::Sym.parse(string) }} - q << true - end - q.pop - q.pop - # 50.times {generated_array.each {|string| JrJackson::Sym.parse(string) }} + 50.times {generated_array.each {|string| JrJackson::Raw.parse_sym(string) }} end - x.report("jackson parse string keys:") do - th1 = Thread.new(generated_array) do |arry| - 50.times {arry.each {|string| JrJackson::Str.parse(string) }} - q << true - end - th2 = Thread.new(generated_array) do |arry| - 50.times {arry.each {|string| JrJackson::Str.parse(string) }} - q << true - end - q.pop - q.pop - # 50.times {generated_array.each {|string| JrJackson::Str.parse(string) }} + x.report("jackson parse raw:") do + 50.times {generated_array.each {|string| JrJackson::Raw.parse_raw(string) }} end x.report("json java generate:") do 50.times {org_array.each {|hsh| hsh.to_json }} end