2009-10-25 05:50:40 +03:00
|
|
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
|
|
|
|
|
|
|
require 'rubygems'
|
|
|
|
require 'json'
|
|
|
|
require 'yajl'
|
|
|
|
require 'benchmark'
|
|
|
|
|
|
|
|
ITER = 1_000
|
|
|
|
|
2009-10-26 18:16:57 +03:00
|
|
|
def setup
|
|
|
|
tiny = t[:ok, :awesome]
|
|
|
|
small = t[:ok, :answers, [42] * 42]
|
2016-05-23 15:09:25 +03:00
|
|
|
large = ["abc" * 1000] * 100
|
2009-10-26 18:16:57 +03:00
|
|
|
complex = [42, {:foo => 'bac' * 100}, t[(1..100).to_a]] * 10
|
2009-10-25 05:50:40 +03:00
|
|
|
|
2009-10-26 18:16:57 +03:00
|
|
|
$tiny_encoded_bert = BERT.encode(tiny)
|
|
|
|
$small_encoded_bert = BERT.encode(small)
|
|
|
|
$large_encoded_bert = BERT.encode(large)
|
|
|
|
$complex_encoded_bert = BERT.encode(complex)
|
2009-10-25 05:50:40 +03:00
|
|
|
|
2009-10-26 18:16:57 +03:00
|
|
|
$tiny_encoded_json = JSON.dump(tiny)
|
|
|
|
$small_encoded_json = JSON.dump(small)
|
|
|
|
$large_encoded_json = JSON.dump(large)
|
|
|
|
$complex_encoded_json = JSON.dump(complex)
|
2009-10-25 05:50:40 +03:00
|
|
|
|
2009-10-26 18:16:57 +03:00
|
|
|
$tiny_encoded_yajl = Yajl::Encoder.encode(tiny)
|
|
|
|
$small_encoded_yajl = Yajl::Encoder.encode(small)
|
|
|
|
$large_encoded_yajl = Yajl::Encoder.encode(large)
|
|
|
|
$complex_encoded_yajl = Yajl::Encoder.encode(complex)
|
2009-10-25 05:50:40 +03:00
|
|
|
|
2009-10-26 18:16:57 +03:00
|
|
|
$tiny_encoded_ruby = Marshal.dump(tiny)
|
|
|
|
$small_encoded_ruby = Marshal.dump(small)
|
|
|
|
$large_encoded_ruby = Marshal.dump(large)
|
|
|
|
$complex_encoded_ruby = Marshal.dump(complex)
|
|
|
|
end
|
2009-10-25 05:50:40 +03:00
|
|
|
|
2009-10-25 05:57:24 +03:00
|
|
|
Benchmark.bm(13) do |bench|
|
2009-10-26 18:16:57 +03:00
|
|
|
pid = fork do
|
|
|
|
require 'bert'
|
|
|
|
raise "Could not load C extension" unless BERT::Decode.impl == 'C'
|
|
|
|
setup
|
|
|
|
puts "BERT C Extension Decoder"
|
|
|
|
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
|
|
|
|
end
|
|
|
|
Process.waitpid(pid)
|
|
|
|
|
|
|
|
pid = fork do
|
|
|
|
Dir.chdir(File.join(File.dirname(__FILE__), *%w[.. ext bert c])) do
|
|
|
|
['*.bundle', '*.o'].each { |pat| `rm -f #{pat}` }
|
|
|
|
end
|
|
|
|
require 'bert'
|
|
|
|
raise "Not using Ruby decoder" unless BERT::Decode.impl == 'Ruby'
|
|
|
|
setup
|
|
|
|
puts "BERT Pure Ruby Decoder"
|
|
|
|
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
|
|
|
|
end
|
|
|
|
Process.waitpid(pid)
|
|
|
|
|
|
|
|
require 'bert'
|
|
|
|
setup
|
|
|
|
|
|
|
|
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)}}
|
2009-10-25 05:50:40 +03:00
|
|
|
puts
|
2009-10-26 18:16:57 +03:00
|
|
|
|
|
|
|
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)}}
|
2009-10-25 05:50:40 +03:00
|
|
|
puts
|
2009-10-26 18:16:57 +03:00
|
|
|
|
|
|
|
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)}}
|
2016-05-19 20:08:33 +03:00
|
|
|
end
|