diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2015-07-10 12:40:23 -0700 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2015-07-10 12:40:23 -0700 |
commit | dcefeff1bb48d82c905265b245c19eb1d83e3f59 (patch) | |
tree | e1a459cd90c0cf53f591ca137274662255a536e1 /lib/ffi_yajl/benchmark/encode.rb | |
parent | aa2afb68a78fed7a71a6d574586202a0377eba25 (diff) | |
download | ffi-yajl-dcefeff1bb48d82c905265b245c19eb1d83e3f59.tar.gz |
down to zero offenses
but 30 cops disabled, lol...
Diffstat (limited to 'lib/ffi_yajl/benchmark/encode.rb')
-rw-r--r-- | lib/ffi_yajl/benchmark/encode.rb | 101 |
1 files changed, 25 insertions, 76 deletions
diff --git a/lib/ffi_yajl/benchmark/encode.rb b/lib/ffi_yajl/benchmark/encode.rb index 8e5c83f..fc03c06 100644 --- a/lib/ffi_yajl/benchmark/encode.rb +++ b/lib/ffi_yajl/benchmark/encode.rb @@ -20,16 +20,6 @@ rescue LoadError puts "INFO: json gem not installed" end begin - require 'psych' -rescue LoadError - puts "INFO: psych gem not installed" -end -begin - require 'active_support' -rescue LoadError - puts "INFO: active_support gem not installed" -end -begin require 'oj' rescue LoadError puts "INFO: oj gem not installed" @@ -45,88 +35,47 @@ module FFI_Yajl 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 { - FFI_Yajl::Encoder.encode(hash) - } - } + ::Benchmark.bmbm do |x| + x.report("FFI_Yajl::Encoder.encode (to a String)") do + times.times { FFI_Yajl::Encoder.encode(hash) } + end ffi_string_encoder = FFI_Yajl::Encoder.new - x.report("FFI_Yajl::Encoder#encode (to a String)") { - times.times { - ffi_string_encoder.encode(hash) - } - } + x.report("FFI_Yajl::Encoder#encode (to a String)") do + times.times { ffi_string_encoder.encode(hash) } + end if defined?(Oj) - x.report("Oj.dump (to a String)") { - times.times { - Oj.dump(hash) - } - } + x.report("Oj.dump (to a String)") do + times.times { Oj.dump(hash) } + end end if defined?(Yajl::Encoder) - x.report("Yajl::Encoder.encode (to a String)") { - times.times { - Yajl::Encoder.encode(hash) - } - } + x.report("Yajl::Encoder.encode (to a String)") do + times.times { Yajl::Encoder.encode(hash) } + end io_encoder = Yajl::Encoder.new - x.report("Yajl::Encoder#encode (to an IO)") { - times.times { - io_encoder.encode(hash, StringIO.new) - } - } + x.report("Yajl::Encoder#encode (to an IO)") do + times.times { io_encoder.encode(hash, StringIO.new) } + end string_encoder = Yajl::Encoder.new - x.report("Yajl::Encoder#encode (to a String)") { - times.times { - string_encoder.encode(hash) - } - } + x.report("Yajl::Encoder#encode (to a String)") do + times.times { string_encoder.encode(hash) } + end end if defined?(JSON) - x.report("JSON.generate") { - times.times { - JSON.generate(hash) - } - } - x.report("JSON.fast_generate") { - times.times { - JSON.fast_generate(hash) - } - } - end - if defined?(Psych) - x.report("Psych.to_json") { - times.times { - Psych.to_json(hash) - } - } - 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 - } - } + x.report("JSON.generate") do + times.times { JSON.generate(hash) } + end + x.report("JSON.fast_generate") do + times.times { JSON.fast_generate(hash) } end end - # if defined?(ActiveSupport::JSON) - # x.report("ActiveSupport::JSON.encode") { - # times.times { - # ActiveSupport::JSON.encode(hash) - # } - # } - # end - } + end end end end |