Sha256: cf3aeeaf5ec11903b2da35581b68abaf1be639a6128d85660a76db689c4c24e3

Contents?: true

Size: 1.54 KB

Versions: 16

Compression:

Stored size: 1.54 KB

Contents

#!/usr/bin/env ruby
# encoding: UTF-8

$: << '.'
$: << File.join(File.dirname(__FILE__), "../lib")
$: << File.join(File.dirname(__FILE__), "../ext")

require 'optparse'
require 'oj'

$verbose = false
$indent = 2
$iter = 100_000
$size = 2

opts = OptionParser.new
opts.on("-v", "verbose")                                    { $verbose = true }
opts.on("-c", "--count [Int]", Integer, "iterations")       { |i| $iter = i }
opts.on("-i", "--indent [Int]", Integer, "indentation")     { |i| $indent = i }
opts.on("-s", "--size [Int]", Integer, "size (~Kbytes)")    { |i| $size = i }
opts.on("-h", "--help", "Show this display")                { puts opts; Process.exit!(0) }
files = opts.parse(ARGV)

$obj = {
  'a' => 'Alpha', # string
  'b' => true,    # boolean
  'c' => 12345,   # number
  'd' => [ true, [false, [-123456789, nil], 3.9676, ['Something else.', false], nil]], # mix it up array
  'e' => { 'zero' => nil, 'one' => 1, 'two' => 2, 'three' => [3], 'four' => [0, 1, 2, 3, 4] }, # hash
  'f' => nil,     # nil
  'h' => { 'a' => { 'b' => { 'c' => { 'd' => {'e' => { 'f' => { 'g' => nil }}}}}}}, # deep hash, not that deep
  'i' => [[[[[[[nil]]]]]]]  # deep array, again, not that deep
}

Oj.default_options = { :indent => $indent, :mode => :strict }

if 0 < $size
  o = $obj
  $obj = []
  (4 * $size).times do
    $obj << o
  end
end

$json = Oj.dump($obj)
GC.start
start = Time.now
$iter.times { Oj.dump($obj) }
duration = Time.now - start
puts "Dumped #{$json.length} byte JSON #{$iter} times in %0.3f seconds or %0.3f iteration/sec." % [duration, $iter / duration]

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
oj-3.14.3 test/perf_dump.rb
oj-3.14.2 test/perf_dump.rb
oj-3.14.1 test/perf_dump.rb
oj-3.14.0 test/perf_dump.rb
oj-3.13.23 test/perf_dump.rb
oj-3.13.22 test/perf_dump.rb
oj-3.13.21 test/perf_dump.rb
oj-3.13.20 test/perf_dump.rb
oj-3.13.19 test/perf_dump.rb
oj-3.13.18 test/perf_dump.rb
oj-3.13.17 test/perf_dump.rb
oj-3.13.16 test/perf_dump.rb
oj-3.13.15 test/perf_dump.rb
oj-3.13.14 test/perf_dump.rb
oj-3.13.13 test/perf_dump.rb
oj-3.13.12 test/perf_dump.rb