eliminate unneeded array traversal and update benches

This commit is contained in:
Tom Preston-Werner 2009-10-24 12:01:18 -07:00
Родитель 873c26fba8
Коммит f0524d23c8
3 изменённых файлов: 16 добавлений и 26 удалений

Просмотреть файл

@ -14,18 +14,21 @@ large = ["abc" * 1000] * 100
complex = [42, {:foo => 'bac' * 100}, t[(1..100).to_a]] * 10
Benchmark.bm do |bench|
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("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("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("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("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("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))}}

Просмотреть файл

@ -35,7 +35,7 @@ Simple C encoder / Ruby decoder
Smarter Ruby decoder
BERT tiny 0.090000 0.000000 0.090000 ( 0.087387)
BERT small 0.790000 0.000000 0.790000 ( 0.850270)
BERT large 4.180000 0.600000 4.780000 ( 4.943164)
BERT complex 18.410000 0.090000 18.500000 ( 19.187804)
BERT tiny 0.070000 0.000000 0.070000 ( 0.075155)
BERT small 0.810000 0.010000 0.820000 ( 0.831905)
BERT large 4.340000 0.600000 4.940000 ( 5.064875)
BERT complex 18.460000 0.070000 18.530000 ( 19.096184)

Просмотреть файл

@ -5,20 +5,7 @@ module BERT
#
# Returns a Ruby object
def self.decode(bert)
simple_ruby = Decode.decode(bert)
convert(simple_ruby)
end
# Convert simple Ruby form into complex Ruby form.
# +item+ is the Ruby object to convert
#
# Returns the converted Ruby object
def self.convert(item)
if item.instance_of?(Array)
item.map { |x| convert(x) }
else
item
end
Decode.decode(bert)
end
end
end