Sha256: b5980923af09ac931d7ffadb83a8c9ea4cd39c4fed7ceb8f27d356baa1217ba8

Contents?: true

Size: 1 KB

Versions: 4

Compression:

Stored size: 1 KB

Contents

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

filename = ARGV[0] || 'benchmark/subjects/contacts.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

4 entries across 4 versions & 2 rubygems

Version Path
brianmario-yajl-ruby-0.5.3 benchmark/parse.rb
brianmario-yajl-ruby-0.5.4 benchmark/parse.rb
brianmario-yajl-ruby-0.5.5 benchmark/parse.rb
yajl-ruby-0.5.5 benchmark/parse.rb