diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2013-11-17 13:38:15 -0800 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2013-11-17 13:38:15 -0800 |
commit | f7f8f268e7aa97bcef04cfb83af23a856aebb8c2 (patch) | |
tree | a912d4d95018b9e380d00713e81a74b6b3edce55 /lib/ffi_yajl/benchmark | |
parent | a2d05c7b645461ac5ce0b54a1960829d07f298be (diff) | |
download | ffi-yajl-f7f8f268e7aa97bcef04cfb83af23a856aebb8c2.tar.gz |
cleanup
Diffstat (limited to 'lib/ffi_yajl/benchmark')
-rw-r--r-- | lib/ffi_yajl/benchmark/encode.rb | 107 |
1 files changed, 54 insertions, 53 deletions
diff --git a/lib/ffi_yajl/benchmark/encode.rb b/lib/ffi_yajl/benchmark/encode.rb index 1e598c4..d86312f 100644 --- a/lib/ffi_yajl/benchmark/encode.rb +++ b/lib/ffi_yajl/benchmark/encode.rb @@ -1,3 +1,6 @@ +# Portions Originally Copyright (c) 2008-2011 Brian Lopez - http://github.com/brianmario +# See MIT-LICENSE + require 'rubygems' require 'benchmark' require 'yajl' @@ -17,77 +20,75 @@ rescue LoadError end module FFI_Yajl - class Benchmark - class Encode + class Benchmark::Encode - def run - #filename = ARGV[0] || 'benchmark/subjects/ohai.json' - filename = File.expand_path(File.join(File.dirname(__FILE__), "subjects", "ohai.json")) - hash = File.open(filename, 'rb') { |f| Yajl::Parser.new.parse(f.read) } + def run + #filename = ARGV[0] || 'benchmark/subjects/ohai.json' + filename = File.expand_path(File.join(File.dirname(__FILE__), "subjects", "ohai.json")) + hash = File.open(filename, 'rb') { |f| Yajl::Parser.new.parse(f.read) } - times = ARGV[1] ? ARGV[1].to_i : 1000 - puts "Starting benchmark encoding #{filename} #{times} times\n\n" - ::Benchmark.bmbm { |x| - io_encoder = Yajl::Encoder.new - string_encoder = Yajl::Encoder.new + times = ARGV[1] ? ARGV[1].to_i : 1000 + puts "Starting benchmark encoding #{filename} #{times} times\n\n" + ::Benchmark.bmbm { |x| + io_encoder = Yajl::Encoder.new + string_encoder = Yajl::Encoder.new - x.report("FFI_Yajl::Encoder.encode (to a String)") { - times.times { - output = FFI_Yajl::Encoder.encode(hash) + x.report("FFI_Yajl::Encoder.encode (to a String)") { + times.times { + output = FFI_Yajl::Encoder.encode(hash) + } } - } - x.report("Yajl::Encoder.encode (to a String)") { - times.times { - output = Yajl::Encoder.encode(hash) + x.report("Yajl::Encoder.encode (to a String)") { + times.times { + output = Yajl::Encoder.encode(hash) + } } - } - x.report("Yajl::Encoder#encode (to an IO)") { - times.times { - io_encoder.encode(hash, StringIO.new) - } - } - x.report("Yajl::Encoder#encode (to a String)") { - times.times { - output = string_encoder.encode(hash) - } - } - if defined?(JSON) - x.report("JSON.generate") { + x.report("Yajl::Encoder#encode (to an IO)") { times.times { - JSON.generate(hash) + io_encoder.encode(hash, StringIO.new) } } - end - if defined?(Psych) - x.report("Psych.to_json") { + x.report("Yajl::Encoder#encode (to a String)") { times.times { - Psych.to_json(hash) + output = string_encoder.encode(hash) } } - if defined?(Psych::JSON::Stream) - x.report("Psych::JSON::Stream") { + if defined?(JSON) + x.report("JSON.generate") { times.times { - io = StringIO.new - stream = Psych::JSON::Stream.new io - stream.start - stream.push hash - stream.finish + JSON.generate(hash) } } end - end - if defined?(ActiveSupport::JSON) - x.report("ActiveSupport::JSON.encode") { - times.times { - ActiveSupport::JSON.encode(hash) + if defined?(Psych) + x.report("Psych.to_json") { + times.times { + Psych.to_json(hash) + } } - } - end - } - end - end + if defined?(Psych::JSON::Stream) + x.report("Psych::JSON::Stream") { + times.times { + io = StringIO.new + stream = Psych::JSON::Stream.new io + stream.start + stream.push hash + stream.finish + } + } + end + end + if defined?(ActiveSupport::JSON) + x.report("ActiveSupport::JSON.encode") { + times.times { + ActiveSupport::JSON.encode(hash) + } + } + end + } + end end end |