protobuf-ruby / beefcake

A sane Google Protocol Buffers library for Ruby
MIT License
276 stars 46 forks source link

Use hash lookup instead of case statements #46

Closed grobie closed 10 years ago

grobie commented 10 years ago

Small improvement I found after using ruby-prof. case statements are usually performance killers in ruby, so better to avoid them.

Before (bench/simple.rb):

                       user     system      total        real
object creation    0.020000   0.000000   0.020000 (  0.015672)
message creation   0.490000   0.000000   0.490000 (  0.492956)
message encoding   2.950000   0.000000   2.950000 (  2.946238)
message decoding   4.110000   0.000000   4.110000 (  4.106664)

After:

                       user     system      total        real
object creation    0.010000   0.000000   0.010000 (  0.015033)
message creation   0.510000   0.000000   0.510000 (  0.507569)
message encoding   2.800000   0.000000   2.800000 (  2.798945)
message decoding   3.850000   0.000000   3.850000 (  3.848129)
bkerley commented 10 years ago

Travis likes it, I like it :) :+1: