Sha256: 1e0d9040201cf9592f16412b2850c2f308b365a0867175a27b46b19122c37542

Contents?: true

Size: 1.08 KB

Versions: 8

Compression:

Stored size: 1.08 KB

Contents

# encoding: UTF-8
require 'rubygems'
require 'benchmark'
require 'yajl_ext'
begin
  require 'json'
rescue LoadError
end
begin
  require 'active_support'
rescue LoadError
end

filename = 'benchmark/subjects/twitter_stream.json'
json = File.new(filename, 'r')

times = ARGV[0] ? ARGV[0].to_i : 100
puts "Starting benchmark parsing JSON stream (#{File.size(filename)} bytes of JSON data with 430 JSON separate strings) #{times} times\n\n"
Benchmark.bmbm { |x|
  parser = Yajl::Parser.new
  parser.on_parse_complete = lambda {|obj|}
  x.report {
    puts "Yajl::Parser#parse"
    times.times {
      json.rewind
      parser.parse(json)
    }
  }
  if defined?(JSON)
    x.report {
      puts "JSON.parse"
      times.times {
        json.rewind
        while chunk = json.gets
          JSON.parse(chunk, :max_nesting => false)
        end
      }
    }
  end
  if defined?(ActiveSupport::JSON)
    x.report {
      puts "ActiveSupport::JSON.decode"
      times.times {
        json.rewind
        while chunk = json.gets
          ActiveSupport::JSON.decode(chunk)
        end
      }
    }
  end
}
json.close

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
yajl-ruby-0.7.4 benchmark/parse_stream.rb
yajl-ruby-0.7.3 benchmark/parse_stream.rb
yajl-ruby-0.7.2 benchmark/parse_stream.rb
yajl-ruby-0.7.1 benchmark/parse_stream.rb
yajl-ruby-0.7.0 benchmark/parse_stream.rb
yajl-ruby-0.6.9 benchmark/parse_stream.rb
yajl-ruby-0.6.8 benchmark/parse_stream.rb
yajl-ruby-0.6.7 benchmark/parse_stream.rb