Sha256: bc38f695db89895488a9ba23b6b8e5fd74d9232a8eaf4db56f5fc72828810015

Contents?: true

Size: 1.29 KB

Versions: 4

Compression:

Stored size: 1.29 KB

Contents

#!/usr/bin/env ruby

# require 'rubygems'
# require 'bigdecimal'
# require 'benchmark'
# require 'thread'
require 'digest'
require 'gson'

# require File.expand_path('lib/jrjackson')

HASH = {:one => nil, :two => nil, :three => nil, :four => {:a => nil, :b => nil, :c =>nil},
:five => {:d => nil, :e => nil},
:six => {:f => nil, :g => nil, :h =>[], :i => nil, :j => nil, :k => nil, :l => nil},
:seven => nil, :eight => [],
:nine => {:m => {:A => nil, :B => nil}}}

def random_string
  Digest::MD5.hexdigest "#{Time.now + rand(999)}"
end

def random_number
  rand 999_999_999
end

def random_float
  random_number + rand
end

def fill_array
  value = []
  5.times do
    value.push send(METHODS[rand(3)])
  end
  value
end

def randomize_entries hsh
  new_hsh = {}
  hsh.each_pair do |key, value|
    case value
    when NilClass
      new_hsh[key] = send METHODS[rand(3)]
    when Hash
      new_hsh[key] = randomize_entries value
    when Array
      new_hsh[key] = fill_array
    end
  end
  new_hsh
end

METHODS = [:random_string, :random_number, :random_float]

array_size = 100000

filename = File.expand_path('benchmarking/fixtures/source4.json')

array = Array.new(array_size)

File.open(filename, 'w') do |f|
  f.write( ::Gson::Encoder.new({}).encode(
      array.map{|e| randomize_entries(HASH.dup)}
    )
  )
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
jrjackson-0.2.4 benchmarking/sourced.rb
jrjackson-0.2.3 benchmarking/sourced.rb
jrjackson-0.2.2 benchmarking/sourced.rb
jrjackson-0.2.1 benchmarking/sourced.rb