Skip to content

Instantly share code, notes, and snippets.

@headius
Created March 18, 2010 02:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save headius/335975 to your computer and use it in GitHub Desktop.
Save headius/335975 to your computer and use it in GitHub Desktop.
def to_serialise(o)
case o
when Java::JavaUtil::ArrayList
o.map { |no| to_serialise(no) }
when Java::JavaUtil::HashMap
o.inject({}) do |h,kv|
h[kv[0].to_s] = to_serialise(kv[1])
h
end
when Array
o.map { |no| to_serialise(no) }
when Hash
o.inject({}) do |h,kv|
h[kv[0].to_s] = to_serialise(kv[1])
h
end
when Fixnum
o
else
o.to_s
end
end
h = {}
1.upto(10000) do |x|
h[x.to_s] = {x => [x]}
end
require 'benchmark'
5.times do
puts Benchmark.measure { to_serialise(h) }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment