Created
March 18, 2010 02:13
-
-
Save headius/335975 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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