Created
February 5, 2013 15:25
-
-
Save FaviusTy/4715118 to your computer and use it in GitHub Desktop.
msgpack<->pstore でベンチしてみたらJSONよりも遅いという結果に
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
# encoding: utf-8 | |
require "pstore" | |
require "msgpack" | |
require "json" | |
require "benchmark" | |
_data = {test: "testdatatestdatatestdata", | |
data: 18358374659302536, | |
_float: 0.1332542572647585, | |
arr: [1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,], | |
nested: {key: "key", arr: [1, 1, 1, 000, 32435, true, false]}, | |
bool: true | |
} | |
data = {} | |
read_obj = nil | |
(1..30000).each do |cycle| | |
data["#{cycle}"] = _data | |
end | |
p "msgpack+pstore" | |
Benchmark.bm(13) do |x| | |
packed = MessagePack.pack(data) | |
x.report("write: ") { | |
db = PStore.new("./backup") | |
db.transaction do | |
db["root"] = MessagePack.unpack(packed) | |
end | |
} | |
x.report("read: ") { | |
db = PStore.new("./backup") | |
db.transaction(true) do | |
read_obj = db["root"] | |
MessagePack.pack(read_obj) | |
end | |
} | |
end | |
p "json" | |
Benchmark.bm(13) do |x| | |
x.report("write: ") { | |
File.open('json', 'w') do |f| | |
f.flock(File::LOCK_EX) | |
f.write JSON.generate(data) | |
f.flock(File::LOCK_UN) | |
end | |
} | |
x.report("read: ") { | |
File.open('json', 'r') do |f| | |
f.flock(File::LOCK_EX) | |
read_obj = JSON.load(f) | |
f.flock(File::LOCK_UN) | |
end | |
} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
多分、msgpackを通すとHash-key値のSymbolがStringになってしまうのが負荷要因と推測する