Snippets

osman a benchmark json parsing

Created by osman a
require 'benchmark'


n = 500
Benchmark.bm do |x|
  customers_file = '/Users/osmanafridi/dev/customer_lobby/api/spec/fixtures/data_uploads/customers.json'
  transactions_file = '/Users/osmanafridi/dev/customer_lobby/api/spec/fixtures/data_uploads/transactions.json'

  x.report('jq:') do
    n.times do
      `jq '.data.row | length' #{customers_file}`.to_i;
      `jq '.data.row | length' #{transactions_file}`.to_i;
    end
  end

  x.report('json_parse:') do
    require 'json'
    n.times do
      JSON.parse(File.read(customers_file))['data']['row'].count
      JSON.parse(File.read(transactions_file))['data']['row'].count
    end
  end

  x.report('yajl_parse:') do
    require 'yajl'
    n.times do
      parser = Yajl::Parser.new
      parser.parse(File.new(customers_file))['data']['row'].count
      parser = Yajl::Parser.new
      parser.parse(File.new(transactions_file))['data']['row'].count
    end
  end


end

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.