Skip to content

Instantly share code, notes, and snippets.

@titanous
Created October 4, 2011 22:01
Show Gist options
  • Select an option

  • Save titanous/1262963 to your computer and use it in GitHub Desktop.

Select an option

Save titanous/1262963 to your computer and use it in GitHub Desktop.
user system total real
BERT int encode 0.010000 0.000000 0.010000 ( 0.013525)
MessagePack int encode 0.000000 0.000000 0.000000 ( 0.000396)
Yajl int encode 0.010000 0.000000 0.010000 ( 0.002894)
BERT int decode 0.000000 0.000000 0.000000 ( 0.000346)
MessagePack int decode 0.000000 0.000000 0.000000 ( 0.000336)
Yajl int decode 0.010000 0.000000 0.010000 ( 0.001949)
BERT array encode 8.010000 0.010000 8.020000 ( 8.022767)
MessagePack array encode 0.060000 0.000000 0.060000 ( 0.063025)
Yajl array encode 0.170000 0.000000 0.170000 ( 0.169183)
BERT array decode 0.020000 0.010000 0.030000 ( 0.020840)
MessagePack array decode 0.020000 0.000000 0.020000 ( 0.024883)
Yajl array decode 0.130000 0.000000 0.130000 ( 0.137456)
BERT hash encode 2.480000 0.000000 2.480000 ( 2.489396)
MessagePack hash encode 0.020000 0.000000 0.020000 ( 0.015464)
Yajl hash encode 0.050000 0.000000 0.050000 ( 0.045070)
BERT hash decode 0.050000 0.000000 0.050000 ( 0.052000)
MessagePack hash decode 0.010000 0.000000 0.010000 ( 0.014237)
Yajl hash decode 0.060000 0.000000 0.060000 ( 0.066382)
BERT boolean encode 0.030000 0.000000 0.030000 ( 0.029918)
MessagePack boolean encode 0.000000 0.000000 0.000000 ( 0.000385)
Yajl boolean encode 0.010000 0.000000 0.010000 ( 0.002552)
BERT boolean decode 0.000000 0.000000 0.000000 ( 0.000569)
MessagePack boolean decode 0.000000 0.000000 0.000000 ( 0.000416)
Yajl boolean decode 0.010000 0.000000 0.010000 ( 0.001556)
BERT string encode 0.010000 0.000000 0.010000 ( 0.015135)
MessagePack string encode 0.010000 0.000000 0.010000 ( 0.000918)
Yajl string encode 0.010000 0.000000 0.010000 ( 0.011787)
BERT string decode 0.000000 0.000000 0.000000 ( 0.000756)
MessagePack string decode 0.000000 0.000000 0.000000 ( 0.000461)
Yajl string decode 0.010000 0.000000 0.010000 ( 0.009283)
require 'benchmark'
require 'msgpack'
require 'bert'
require 'json'
require 'yajl'
module MessagePack
def self.decode(val)
unpack(val)
end
def self.encode(val)
pack(val)
end
end
module Yajl
def self.decode(val)
self.load(val)
end
def self.encode(val)
dump(val)
end
end
types = %w(int array hash boolean string)
values = [1024*1000, (0..1000).to_a, Hash[(0..100).to_a.zip((0..100).to_a)], true, 'foo'*1000]
values_hash = Hash[types.zip(values)]
serializers = [BERT, MessagePack, Yajl]
iterations = 1000
encoded_values = {}
serializers.each do |serializer|
encoded_values[serializer] = Hash[types.zip(values.map{|v| serializer.encode(v)})]
end
Benchmark.bmbm do |x|
types.each do |type|
serializers.each do |serializer|
x.report("#{serializer} #{type} encode") { iterations.times { serializer.encode(values_hash[type]) } }
end
serializers.each do |serializer|
x.report("#{serializer} #{type} decode") { iterations.times { serializer.decode(encoded_values[serializer][type]) } }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment