Skip to content
Browse files

add encoder benchmarker

  • Loading branch information...
1 parent 92b1b82 commit 1bb3ed514ebcd93f01ce22c7e09ac76dddf556ea @mojombo committed Oct 24, 2009
Showing with 49 additions and 13 deletions.
  1. +13 −13 bench/decode_bench.rb
  2. +36 −0 bench/encode_bench.rb
View
26 bench/decode_bench.rb
@@ -33,24 +33,24 @@
large_encoded_ruby = Marshal.dump(large)
complex_encoded_ruby = Marshal.dump(complex)
-Benchmark.bm do |bench|
- bench.report("BERT tiny") {ITER.times {BERT.decode(tiny_encoded_bert)}}
- bench.report("BERT small") {ITER.times {BERT.decode(small_encoded_bert)}}
- bench.report("BERT large") {ITER.times {BERT.decode(large_encoded_bert)}}
+Benchmark.bm(13) do |bench|
+ bench.report("BERT tiny") {ITER.times {BERT.decode(tiny_encoded_bert)}}
+ bench.report("BERT small") {ITER.times {BERT.decode(small_encoded_bert)}}
+ bench.report("BERT large") {ITER.times {BERT.decode(large_encoded_bert)}}
bench.report("BERT complex") {ITER.times {BERT.decode(complex_encoded_bert)}}
puts
- bench.report("JSON tiny") {ITER.times {JSON.load(tiny_encoded_json)}}
- bench.report("JSON small") {ITER.times {JSON.load(small_encoded_json)}}
- bench.report("JSON large") {ITER.times {JSON.load(large_encoded_json)}}
+ bench.report("JSON tiny") {ITER.times {JSON.load(tiny_encoded_json)}}
+ bench.report("JSON small") {ITER.times {JSON.load(small_encoded_json)}}
+ bench.report("JSON large") {ITER.times {JSON.load(large_encoded_json)}}
bench.report("JSON complex") {ITER.times {JSON.load(complex_encoded_json)}}
puts
- bench.report("YAJL tiny") {ITER.times {Yajl::Parser.parse(tiny_encoded_yajl)}}
- bench.report("YAJL small") {ITER.times {Yajl::Parser.parse(small_encoded_yajl)}}
- bench.report("YAJL large") {ITER.times {Yajl::Parser.parse(large_encoded_yajl)}}
+ bench.report("YAJL tiny") {ITER.times {Yajl::Parser.parse(tiny_encoded_yajl)}}
+ bench.report("YAJL small") {ITER.times {Yajl::Parser.parse(small_encoded_yajl)}}
+ bench.report("YAJL large") {ITER.times {Yajl::Parser.parse(large_encoded_yajl)}}
bench.report("YAJL complex") {ITER.times {Yajl::Parser.parse(complex_encoded_yajl)}}
puts
- bench.report("Ruby tiny") {ITER.times {Marshal.load(tiny_encoded_ruby)}}
- bench.report("Ruby small") {ITER.times {Marshal.load(small_encoded_ruby)}}
- bench.report("Ruby large") {ITER.times {Marshal.load(large_encoded_ruby)}}
+ bench.report("Ruby tiny") {ITER.times {Marshal.load(tiny_encoded_ruby)}}
+ bench.report("Ruby small") {ITER.times {Marshal.load(small_encoded_ruby)}}
+ bench.report("Ruby large") {ITER.times {Marshal.load(large_encoded_ruby)}}
bench.report("Ruby complex") {ITER.times {Marshal.load(complex_encoded_ruby)}}
end
View
36 bench/encode_bench.rb
@@ -0,0 +1,36 @@
+$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
+
+require 'rubygems'
+require 'bert'
+require 'json'
+require 'yajl'
+require 'benchmark'
+
+ITER = 1_000
+
+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
+
+Benchmark.bm(13) do |bench|
+ bench.report("BERT tiny") {ITER.times {BERT.encode(tiny)}}
+ bench.report("BERT small") {ITER.times {BERT.encode(small)}}
+ bench.report("BERT large") {ITER.times {BERT.encode(large)}}
+ bench.report("BERT complex") {ITER.times {BERT.encode(complex)}}
+ puts
+ bench.report("JSON tiny") {ITER.times {JSON.dump(tiny)}}
+ bench.report("JSON small") {ITER.times {JSON.dump(small)}}
+ bench.report("JSON large") {ITER.times {JSON.dump(large)}}
+ bench.report("JSON complex") {ITER.times {JSON.dump(complex)}}
+ puts
+ bench.report("JSON tiny") {ITER.times {Yajl::Encoder.encode(tiny)}}
+ bench.report("JSON small") {ITER.times {Yajl::Encoder.encode(small)}}
+ bench.report("JSON large") {ITER.times {Yajl::Encoder.encode(large)}}
+ bench.report("JSON complex") {ITER.times {Yajl::Encoder.encode(complex)}}
+ puts
+ bench.report("Ruby tiny") {ITER.times {Marshal.dump(tiny)}}
+ bench.report("Ruby small") {ITER.times {Marshal.dump(small)}}
+ bench.report("Ruby large") {ITER.times {Marshal.dump(large)}}
+ bench.report("Ruby complex") {ITER.times {Marshal.dump(complex)}}
+end

0 comments on commit 1bb3ed5

Please sign in to comment.
Something went wrong with that request. Please try again.