Sha256: 4be4b0440b41a9ec3fbaa51317c297a66ad16b4debcc6d42d01037d9d18d8af2

Contents?: true

Size: 1021 Bytes

Versions: 24

Compression:

Stored size: 1021 Bytes

Contents

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

filename = ARGV[0] || 'benchmark/subjects/ohai.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|
  io_parser = Yajl::Parser.new
  x.report {
    puts "Yajl::Parser#parse (from an IO)"
    times.times {
      json.rewind
      io_parser.parse(json)
    }
  }
  string_parser = Yajl::Parser.new
  x.report {
    puts "Yajl::Parser#parse (from a String)"
    times.times {
      json.rewind
      string_parser.parse(json.read)
    }
  }
  x.report {
    puts "JSON.parse"
    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

24 entries across 24 versions & 5 rubygems

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