Sha256: 6390b59223a28b34c7d20feb89ff118301c42d184b50fb998f26708cb3004f0d

Contents?: true

Size: 804 Bytes

Versions: 1

Compression:

Stored size: 804 Bytes

Contents

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

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

# warm up the filesystem
json.read
json.rewind

times = ARGV[1] ? ARGV[1].to_i : 1
puts "Starting benchmark parsing #{File.size(filename)} bytes of JSON data #{times} times\n\n"
Benchmark.bm { |x|
  x.report {
    puts "Yajl::Native.parse (C)"
    times.times {
      json.rewind
      Yajl::Stream.parse(json)
    }
  }
  x.report {
    puts "JSON.parser"
    times.times {
      json.rewind
      JSON.parse(json.read, :max_nesting => false)
    }
  }
  x.report {
    puts "ActiveSupport::JSON.decode"
    times.times {
      json.rewind
      ActiveSupport::JSON.decode(json.read)
    }
  }
}
json.close

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
brianmario-yajl-ruby-0.4.0 benchmark/stream.rb