Sha256: 6c21e187904c5783396f08d57a72a7e33ab6661706c1b0a6df445d734312b821

Contents?: true

Size: 1.93 KB

Versions: 26

Compression:

Stored size: 1.93 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 'yaml'
require 'yajl'
begin
  require 'json'
rescue LoadError
end
begin
  require 'psych'
rescue LoadError
end
begin
  require 'active_support'
rescue LoadError
end

filename = ARGV[0] || 'benchmark/subjects/item.json'
json = File.new(filename, 'r')

times = ARGV[1] ? ARGV[1].to_i : 10_000
puts "Starting benchmark parsing #{File.size(filename)} bytes of JSON data #{times} times\n\n"
Benchmark.bmbm { |x|
  io_parser = Yajl::Parser.new
  io_parser.on_parse_complete = lambda {|obj|} if times > 1
  x.report {
    puts "Yajl::Parser#parse (from an IO)"
    times.times {
      json.rewind
      io_parser.parse(json)
    }
  }
  string_parser = Yajl::Parser.new
  string_parser.on_parse_complete = lambda {|obj|} if times > 1
  x.report {
    puts "Yajl::Parser#parse (from a String)"
    times.times {
      json.rewind
      string_parser.parse(json.read)
    }
  }
  if defined?(JSON)
    x.report {
      puts "JSON.parse"
      times.times {
        json.rewind
        JSON.parse(json.read, :max_nesting => false)
      }
    }
  end
  if defined?(ActiveSupport::JSON)
    x.report {
      puts "ActiveSupport::JSON.decode"
      times.times {
        json.rewind
        ActiveSupport::JSON.decode(json.read)
      }
    }
  end
  x.report {
    puts "YAML.load (from an IO)"
    times.times {
      json.rewind
      YAML.load(json)
    }
  }
  x.report {
    puts "YAML.load (from a String)"
    times.times {
      json.rewind
      YAML.load(json.read)
    }
  }
  if defined?(Psych)
    x.report {
      puts "Psych.load (from an IO)"
      times.times {
        json.rewind
        Psych.load(json)
      }
    }
    x.report {
      puts "Psych.load (from a String)"
      times.times {
        json.rewind
        Psych.load(json.read)
      }
    }
  end
}
json.close

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/parse.rb
fluent-plugin-openlineage-light-0.1.4 vendor/bundle/ruby/3.3.0/gems/yajl-ruby-1.4.3/benchmark/parse.rb
fluent-plugin-openlineage-light-0.1.3 vendor/bundle/ruby/3.3.0/gems/yajl-ruby-1.4.3/benchmark/parse.rb
fluent-plugin-openlineage-0.1.0 vendor/bundle/ruby/3.3.0/gems/yajl-ruby-1.4.3/benchmark/parse.rb
fluent-plugin-google-cloud-logging-on-prem-0.1.0 vendor/ruby/3.1.0/gems/yajl-ruby-1.4.3/benchmark/parse.rb
yajl-ruby-1.4.3 benchmark/parse.rb
yajl-ruby-1.4.2 benchmark/parse.rb
yajl-ruby-1.4.1 benchmark/parse.rb
yajl-ruby-1.4.0 benchmark/parse.rb
yajl-ruby-1.2.3 benchmark/parse.rb
yajl-ruby-1.3.1 benchmark/parse.rb
fluent-plugin-detect-memb-exceptions-0.0.2 vendor/bundle/ruby/2.0.0/gems/yajl-ruby-1.3.0/benchmark/parse.rb
fluent-plugin-detect-memb-exceptions-0.0.1 vendor/bundle/ruby/2.0.0/gems/yajl-ruby-1.3.0/benchmark/parse.rb
yajl-ruby-1.2.2 benchmark/parse.rb
yajl-ruby-1.3.0 benchmark/parse.rb
tdiary-4.2.1 vendor/bundle/ruby/2.2.0/gems/yajl-ruby-1.2.1/benchmark/parse.rb
yajl-ruby-1.2.1 benchmark/parse.rb
yajl-ruby-1.2.0 benchmark/parse.rb
yajl-ruby-zenjoy-1.1.0 benchmark/parse.rb
yajl-ruby-maglev--1.1.0 benchmark/parse.rb