/
encode_bench.rb
36 lines (32 loc) · 1.41 KB
/
encode_bench.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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