mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-10-24 09:12:30 +02:00
lang/c/msgpack: added Messagepack, a binary-based efficient data interchange format.
git-svn-id: file:///Users/frsyuki/project/msgpack-git/svn/x@48 5a5092ae-2292-43ba-b2d5-dcab9c1a2731
This commit is contained in:
60
ruby/bench.rb
Normal file
60
ruby/bench.rb
Normal file
@@ -0,0 +1,60 @@
|
||||
require 'rubygems'
|
||||
require 'json'
|
||||
require 'msgpack'
|
||||
|
||||
def show10(str)
|
||||
puts "#{str.length/1024} KB"
|
||||
puts str[0, 10].unpack('C*').map{|x|"%02x"%x}.join(' ') + " ..."
|
||||
end
|
||||
|
||||
ary = []
|
||||
i = 0
|
||||
while i < (1<<23)
|
||||
ary << (1<<23)
|
||||
#ary << i
|
||||
i += 1
|
||||
end
|
||||
|
||||
GC.start
|
||||
|
||||
puts "----"
|
||||
puts "MessagePack"
|
||||
a = Time.now
|
||||
packed = MessagePack::pack(ary)
|
||||
b = Time.now
|
||||
show10(packed)
|
||||
puts "#{b-a} sec."
|
||||
|
||||
GC.start
|
||||
|
||||
puts "----"
|
||||
puts "JSON"
|
||||
a = Time.now
|
||||
json = ary.to_json
|
||||
b = Time.now
|
||||
show10(json)
|
||||
puts "#{b-a} sec."
|
||||
|
||||
ary = nil
|
||||
GC.start
|
||||
|
||||
|
||||
puts "----"
|
||||
puts "MessagePack"
|
||||
a = Time.now
|
||||
ary = MessagePack::unpack(packed)
|
||||
b = Time.now
|
||||
puts "#{b-a} sec."
|
||||
|
||||
ary = nil
|
||||
GC.start
|
||||
|
||||
|
||||
puts "----"
|
||||
puts "JSON"
|
||||
a = Time.now
|
||||
ary = JSON::load(json)
|
||||
b = Time.now
|
||||
puts "#{b-a} sec."
|
||||
|
||||
|
||||
Reference in New Issue
Block a user