diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2013-11-17 14:19:42 -0800 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2013-11-17 14:19:42 -0800 |
commit | 241e8217f7ee19759c8f59d0fd0f3bdcee883875 (patch) | |
tree | 4dbee1ab0e2bf238330b0c7fa9534a5b9b67f1f0 /lib/ffi_yajl/benchmark | |
parent | b9ca0bb55c70cc179939134ce212dde86465488b (diff) | |
download | ffi-yajl-241e8217f7ee19759c8f59d0fd0f3bdcee883875.tar.gz |
fix bmark binary again
Diffstat (limited to 'lib/ffi_yajl/benchmark')
-rw-r--r-- | lib/ffi_yajl/benchmark/encode.rb | 110 |
1 files changed, 56 insertions, 54 deletions
diff --git a/lib/ffi_yajl/benchmark/encode.rb b/lib/ffi_yajl/benchmark/encode.rb index cd77c50..16bb7c7 100644 --- a/lib/ffi_yajl/benchmark/encode.rb +++ b/lib/ffi_yajl/benchmark/encode.rb @@ -23,78 +23,80 @@ rescue LoadError end module FFI_Yajl - class Benchmark::Encode + class Benchmark + class 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| + times = ARGV[1] ? ARGV[1].to_i : 1000 + puts "Starting benchmark encoding #{filename} #{times} times\n\n" + ::Benchmark.bmbm { |x| - 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) - } - } - - if defined?(Yajl::Encoder) - io_encoder = Yajl::Encoder.new - x.report("Yajl::Encoder#encode (to an IO)") { + x.report("FFI_Yajl::Encoder.encode (to a String)") { times.times { - io_encoder.encode(hash, StringIO.new) + output = FFI_Yajl::Encoder.encode(hash) } } - string_encoder = Yajl::Encoder.new - x.report("Yajl::Encoder#encode (to a String)") { + x.report("Yajl::Encoder.encode (to a String)") { times.times { - output = string_encoder.encode(hash) + output = Yajl::Encoder.encode(hash) } } - end - if defined?(JSON) - x.report("JSON.generate") { - times.times { - JSON.generate(hash) + if defined?(Yajl::Encoder) + io_encoder = Yajl::Encoder.new + x.report("Yajl::Encoder#encode (to an IO)") { + times.times { + io_encoder.encode(hash, StringIO.new) + } } - } - end - if defined?(Psych) - x.report("Psych.to_json") { - times.times { - Psych.to_json(hash) + + string_encoder = Yajl::Encoder.new + x.report("Yajl::Encoder#encode (to a String)") { + times.times { + output = string_encoder.encode(hash) + } } - } - if defined?(Psych::JSON::Stream) - x.report("Psych::JSON::Stream") { + end + + 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 - } + 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 |