From 4fa5e2e2d34b3760281e738fd30c17d6f1ca31c3 Mon Sep 17 00:00:00 2001 From: Matt Burke Date: Fri, 21 Apr 2017 09:03:53 -0400 Subject: [PATCH] Benchmark dat msgpack --- Gemfile.lock | 5 ++--- bench/bench.rb | 16 ++++++++++++++-- bert.gemspec | 1 + 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 3f4e392..c540cb1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -7,6 +7,7 @@ GEM remote: https://rubygems.org/ specs: git (1.3.0) + msgpack (1.1.0) power_assert (0.4.1) rake (12.0.0) rake-compiler (0.9.9) @@ -22,11 +23,9 @@ PLATFORMS DEPENDENCIES bert! git + msgpack rake rake-compiler (~> 0.9.0) test-unit thoughtbot-shoulda yajl-ruby - -BUNDLED WITH - 1.13.7 diff --git a/bench/bench.rb b/bench/bench.rb index 1d77b8c..5f0878e 100644 --- a/bench/bench.rb +++ b/bench/bench.rb @@ -3,6 +3,7 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) require 'rubygems' require 'bert' require 'json' +require 'msgpack' require 'yajl' require 'benchmark' @@ -12,25 +13,36 @@ tiny = t[:ok, :awesome] small = t[:ok, :answers, [42] * 42] large = ["abc" * 1000] * 100 complex = [42, {:foo => 'bac' * 100}, t[(1..100).to_a]] * 10 +long_array = {:a => ["a"]*1000} -Benchmark.bm do |bench| +Benchmark.bm(30) do |bench| bench.report("BERT tiny") {ITER.times {BERT.decode(BERT.encode(tiny))}} bench.report("BERT small") {ITER.times {BERT.decode(BERT.encode(small))}} bench.report("BERT large") {ITER.times {BERT.decode(BERT.encode(large))}} bench.report("BERT complex") {ITER.times {BERT.decode(BERT.encode(complex))}} + bench.report("BERT long array") {ITER.times {BERT.decode(BERT.encode(long_array))}} bench.report("JSON tiny") {ITER.times {JSON.load(JSON.dump(tiny))}} bench.report("JSON small") {ITER.times {JSON.load(JSON.dump(small))}} bench.report("JSON large") {ITER.times {JSON.load(JSON.dump(large))}} bench.report("JSON complex") {ITER.times {JSON.load(JSON.dump(complex))}} + bench.report("JSON long array") {ITER.times {JSON.load(JSON.dump(long_array))}} bench.report("YAJL tiny") {ITER.times {Yajl::Parser.parse(Yajl::Encoder.encode(tiny))}} bench.report("YAJL small") {ITER.times {Yajl::Parser.parse(Yajl::Encoder.encode(small))}} bench.report("YAJL large") {ITER.times {Yajl::Parser.parse(Yajl::Encoder.encode(large))}} bench.report("YAJL complex") {ITER.times {Yajl::Parser.parse(Yajl::Encoder.encode(complex))}} + bench.report("YAJL long array") {ITER.times {Yajl::Parser.parse(Yajl::Encoder.encode(long_array))}} bench.report("Ruby tiny") {ITER.times {Marshal.load(Marshal.dump(tiny))}} bench.report("Ruby small") {ITER.times {Marshal.load(Marshal.dump(small))}} bench.report("Ruby large") {ITER.times {Marshal.load(Marshal.dump(large))}} bench.report("Ruby complex") {ITER.times {Marshal.load(Marshal.dump(complex))}} -end \ No newline at end of file + bench.report("Ruby long array") {ITER.times {Marshal.load(Marshal.dump(long_array))}} + + bench.report("Msgpack tiny") {ITER.times {MessagePack.unpack(MessagePack.pack(tiny))}} + bench.report("Msgpack small") {ITER.times {MessagePack.unpack(MessagePack.pack(small))}} + bench.report("Msgpack large") {ITER.times {MessagePack.unpack(MessagePack.pack(large))}} + bench.report("Msgpack complex") {ITER.times {MessagePack.unpack(MessagePack.pack(complex))}} + bench.report("Msgpack long array") {ITER.times {MessagePack.unpack(MessagePack.pack(long_array))}} +end diff --git a/bert.gemspec b/bert.gemspec index bdd4c85..d6d8b6a 100644 --- a/bert.gemspec +++ b/bert.gemspec @@ -23,6 +23,7 @@ Gem::Specification.new do |s| s.add_development_dependency "thoughtbot-shoulda" s.add_development_dependency "git" + s.add_development_dependency "msgpack" s.add_development_dependency "rake" s.add_development_dependency "rake-compiler", "~> 0.9.0" s.add_development_dependency "yajl-ruby"