Sha256: 9f158b246d6bc15afb73c3fc560150bc2408975bfeb202544de3cd8581d8c3be

Contents?: true

Size: 1.39 KB

Versions: 24

Compression:

Stored size: 1.39 KB

Contents

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

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

#require 'test/unit'
require 'optparse'
require 'yajl'
require 'oj'

$indent = 2

opts = OptionParser.new
opts.on("-h", "--help", "Show this display")                { puts opts; Process.exit!(0) }
files = opts.parse(ARGV)

iter = 100000
s = %{
{ "class": "Foo::Bar",
  "attr1": [ true, [false, [12345, null], 3.967, ["something", false], null]],
  "attr2": { "one": 1 }
}
}

start = Time.now
iter.times do
  Oj.load(s)
end
oj_dt = Time.now - start
puts "%d Oj.load()s in %0.3f seconds or %0.1f loads/msec" % [iter, oj_dt, iter/oj_dt/1000.0]

start = Time.now
iter.times do
  Yajl::Parser.parse(s)
end
yajl_dt = Time.now - start
puts "%d Yajl::Parser.parse()s in %0.3f seconds or %0.1f parses/msec" % [iter, yajl_dt, iter/yajl_dt/1000.0]

puts "Oj is %0.1f times faster than YAJL at parsing." % [yajl_dt / oj_dt]


obj = Oj.load(s)
start = Time.now
iter.times do
  Oj.dump(obj)
end
oj_dt = Time.now - start
puts "%d Oj.dump()s in %0.3f seconds or %0.1f dumps/msec" % [iter, oj_dt, iter/oj_dt/1000.0]

start = Time.now
iter.times do
  Yajl::Encoder.encode(obj)
end
yajl_dt = Time.now - start
puts "%d Yajl::Encoder.encode()s in %0.3f seconds or %0.1f encodes/msec" % [iter, yajl_dt, iter/yajl_dt/1000.0]

puts "Oj is %0.1f times faster than YAJL at dumping." % [yajl_dt / oj_dt]

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
oj-1.3.4 test/foo.rb
oj-1.3.0 test/foo.rb
oj-1.2.13 test/foo.rb
oj-1.2.12 test/foo.rb
oj-1.2.10 test/foo.rb
oj-1.2.8 test/foo.rb
oj-1.2.7 test/foo.rb
oj-1.2.6 test/foo.rb
oj-1.2.3 test/foo.rb
oj-1.2.1 test/foo.rb
oj-1.2.0 test/foo.rb
oj-1.1.0 test/foo.rb
oj-1.0.6 test/foo.rb
oj-1.0.5 test/foo.rb
oj-1.0.4 test/foo.rb
oj-1.0.3 test/foo.rb
oj-1.0.2 test/foo.rb
oj-1.0.1 test/foo.rb
oj-1.0.0 test/foo.rb
oj-0.9.0 test/foo.rb