Skip to content

Instantly share code, notes, and snippets.

@dekart
Created September 11, 2009 11:16
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 dekart/185235 to your computer and use it in GitHub Desktop.
Save dekart/185235 to your computer and use it in GitHub Desktop.
require "yaml"
require "benchmark"
class SomeClass
def initialize(value)
@value = value
end
end
hash = {
:symbol => "symbol value",
"text" => "text value",
123 => ["asd", :asd, 123],
:class => SomeClass.new(["asd", 123]),
[123, "asd"] => Array.new(10){|i| SomeClass.new(i) }
}
CYCLES = 10000
Benchmark.bm(20) do |bm|
bm.report("Marshal dump") do
CYCLES.times do
@marshal_code = Marshal.dump(hash)
end
end
bm.report("Marshal load") do
CYCLES.times do
Marshal.load(@marshal_code)
end
end
bm.report("YAML dump") do
CYCLES.times do
@yaml_code = YAML.dump(hash)
end
end
bm.report("YAML load") do
CYCLES.times do
YAML.load(@yaml_code)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment