2009-10-24 11:49:44 +04:00
|
|
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
|
|
|
|
|
|
|
require 'rubygems'
|
|
|
|
require 'bert'
|
|
|
|
require 'json'
|
|
|
|
require 'yajl'
|
|
|
|
require 'benchmark'
|
|
|
|
|
|
|
|
ITER = 1_000
|
2017-05-26 21:27:43 +03:00
|
|
|
LONG_ITER = 100
|
2009-10-24 11:49:44 +04:00
|
|
|
|
|
|
|
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
|
2017-05-26 21:27:43 +03:00
|
|
|
long_array = {:a => ["a", :a, Time.now, /a/]*1000}
|
2009-10-24 11:49:44 +04:00
|
|
|
|
2017-04-21 16:03:53 +03:00
|
|
|
Benchmark.bm(30) do |bench|
|
2017-04-27 21:30:54 +03:00
|
|
|
[:v1, :v2, :v3].each do |v|
|
2017-04-21 17:36:27 +03:00
|
|
|
BERT::Encode.version = v
|
|
|
|
bench.report("BERT #{v} tiny") {ITER.times {BERT.decode(BERT.encode(tiny))}}
|
|
|
|
bench.report("BERT #{v} small") {ITER.times {BERT.decode(BERT.encode(small))}}
|
|
|
|
bench.report("BERT #{v} large") {ITER.times {BERT.decode(BERT.encode(large))}}
|
|
|
|
bench.report("BERT #{v} complex") {ITER.times {BERT.decode(BERT.encode(complex))}}
|
2017-05-26 21:27:43 +03:00
|
|
|
bench.report("BERT #{v} long array") {LONG_ITER.times {BERT.decode(BERT.encode(long_array))}}
|
2017-04-21 17:36:27 +03:00
|
|
|
end
|
2009-10-24 23:01:18 +04:00
|
|
|
|
2009-10-24 11:49:44 +04:00
|
|
|
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))}}
|
2017-05-26 21:27:43 +03:00
|
|
|
bench.report("JSON long array") {LONG_ITER.times {JSON.load(JSON.dump(long_array))}}
|
2009-10-24 23:01:18 +04:00
|
|
|
|
2009-10-24 11:49:44 +04:00
|
|
|
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))}}
|
2017-05-26 21:27:43 +03:00
|
|
|
bench.report("YAJL long array") {LONG_ITER.times {Yajl::Parser.parse(Yajl::Encoder.encode(long_array))}}
|
2009-10-24 23:01:18 +04:00
|
|
|
|
2009-10-24 11:49:44 +04:00
|
|
|
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))}}
|
2017-05-26 21:27:43 +03:00
|
|
|
bench.report("Ruby long array") {LONG_ITER.times {Marshal.load(Marshal.dump(long_array))}}
|
2017-04-21 16:03:53 +03:00
|
|
|
end
|