Sha256: 07b4bb1459720623e2b0349b4324c8685e4f69008bcf8322c8c2ba7ca13e8a5c

Contents?: true

Size: 1 KB

Versions: 29

Compression:

Stored size: 1 KB

Contents

# encoding: UTF-8
require 'rubygems'
require 'benchmark'
require 'yajl_ext'
require 'json'
# require 'activesupport'

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

# warm up the filesystem
json.read
json.rewind

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

Version data entries

29 entries across 29 versions & 5 rubygems

Version Path
brianmario-yajl-ruby-0.5.10 benchmark/parse_stream.rb
brianmario-yajl-ruby-0.5.11 benchmark/parse_stream.rb
brianmario-yajl-ruby-0.5.12 benchmark/parse_stream.rb
brianmario-yajl-ruby-0.5.2 benchmark/parse_stream.rb
brianmario-yajl-ruby-0.5.3 benchmark/parse_stream.rb
brianmario-yajl-ruby-0.5.4 benchmark/parse_stream.rb
brianmario-yajl-ruby-0.5.5 benchmark/parse_stream.rb
brianmario-yajl-ruby-0.5.6 benchmark/parse_stream.rb
brianmario-yajl-ruby-0.5.7 benchmark/parse_stream.rb
brianmario-yajl-ruby-0.5.8 benchmark/parse_stream.rb
brianmario-yajl-ruby-0.5.9 benchmark/parse_stream.rb
brianmario-yajl-ruby-0.6.0 benchmark/parse_stream.rb
brianmario-yajl-ruby-0.6.1 benchmark/parse_stream.rb
brianmario-yajl-ruby-0.6.3 benchmark/parse_stream.rb
jdg-yajl-ruby-0.5.12 benchmark/parse_stream.rb
oortle-yajl-ruby-0.5.8 benchmark/parse_stream.rb
filipegiusti-yajl-ruby-0.6.4 benchmark/parse_stream.rb
yajl-ruby-0.6.3 benchmark/parse_stream.rb
yajl-ruby-0.6.2 benchmark/parse_stream.rb
yajl-ruby-0.6.0 benchmark/parse_stream.rb