-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathyaml-test.rb
42 lines (38 loc) · 914 Bytes
/
yaml-test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
require 'benchmark'
require 'yaml'
require 'json' # gem install json
hash = {
:name => 'Xavier',
:age => 24,
:likes => ["Climbing", "Computers", "Food"]}
n = 10000
marshal_hash = Marshal.dump(hash)
yaml_hash = YAML.dump(hash)
json_hash = JSON.dump(hash)
Benchmark.bm do |b|
b.report("Marshal serialize") do
n.times { Marshal.dump(hash) }
end
b.report("Marshal deserialize") do
n.times { Marshal.load(marshal_hash) }
end
b.report("JSON serialize") do
n.times { JSON.dump(hash) }
end
b.report("JSON deserialize") do
n.times { JSON.load(json_hash) }
end
b.report("YAML serialize") do
n.times { YAML.dump(hash) }
end
b.report("YAML deserialize") do
n.times { YAML.load(yaml_hash) }
end
require 'psych'
b.report("Psych serialize") do
n.times { Psych.dump(hash) }
end
b.report("Psych deserialize") do
n.times { Psych.load(yaml_hash) }
end
end