Sha256: f226c1ef37fe9593e56a12251083faccad918a813eb76dc46e5f44cf3907b98b

Contents?: true

Size: 1.56 KB

Versions: 26

Compression:

Stored size: 1.56 KB

Contents

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

require 'rubygems'
require 'benchmark'
require 'yajl'
require 'stringio'
begin
  require 'json'
rescue LoadError
end
begin
  require 'psych'
rescue LoadError
end
begin
  require 'active_support'
rescue LoadError
end

filename = ARGV[0] || 'benchmark/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

  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") {
      times.times {
        JSON.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
        }
      }
    end
  end
  if defined?(ActiveSupport::JSON)
    x.report("ActiveSupport::JSON.encode") {
      times.times {
        ActiveSupport::JSON.encode(hash)
      }
    }
  end
}

Version data entries

26 entries across 26 versions & 9 rubygems

Version Path
fluent-plugin-nuopenlineage-light-0.1.0 vendor/bundle/ruby/3.3.0/gems/yajl-ruby-1.4.3/benchmark/encode.rb
fluent-plugin-openlineage-light-0.1.4 vendor/bundle/ruby/3.3.0/gems/yajl-ruby-1.4.3/benchmark/encode.rb
fluent-plugin-openlineage-light-0.1.3 vendor/bundle/ruby/3.3.0/gems/yajl-ruby-1.4.3/benchmark/encode.rb
fluent-plugin-openlineage-0.1.0 vendor/bundle/ruby/3.3.0/gems/yajl-ruby-1.4.3/benchmark/encode.rb
fluent-plugin-google-cloud-logging-on-prem-0.1.0 vendor/ruby/3.1.0/gems/yajl-ruby-1.4.3/benchmark/encode.rb
yajl-ruby-1.4.3 benchmark/encode.rb
yajl-ruby-1.4.2 benchmark/encode.rb
yajl-ruby-1.4.1 benchmark/encode.rb
yajl-ruby-1.4.0 benchmark/encode.rb
yajl-ruby-1.2.3 benchmark/encode.rb
yajl-ruby-1.3.1 benchmark/encode.rb
fluent-plugin-detect-memb-exceptions-0.0.2 vendor/bundle/ruby/2.0.0/gems/yajl-ruby-1.3.0/benchmark/encode.rb
fluent-plugin-detect-memb-exceptions-0.0.1 vendor/bundle/ruby/2.0.0/gems/yajl-ruby-1.3.0/benchmark/encode.rb
yajl-ruby-1.2.2 benchmark/encode.rb
yajl-ruby-1.3.0 benchmark/encode.rb
tdiary-4.2.1 vendor/bundle/ruby/2.2.0/gems/yajl-ruby-1.2.1/benchmark/encode.rb
yajl-ruby-1.2.1 benchmark/encode.rb
yajl-ruby-1.2.0 benchmark/encode.rb
yajl-ruby-zenjoy-1.1.0 benchmark/encode.rb
yajl-ruby-maglev--1.1.0 benchmark/encode.rb