title: Which is faster in ruby - a hash lookup or a function with a case statement?
body: <p>We have a few places in a time-critical script where we convert old IDs into strings.  At the moment, we use case statements inside a function, like so:</p>
  
  <pre><code>def get_name id
    case id
      when 1
        "one thing"
      when 3
        "other thing"
      else
        "default thing"
    end
  end
  </code></pre>
  
  <p>I'm considering replacing this with a hash lookup, like so:</p>
  
  <pre><code>NAMES = {
    1 =&gt; "one thing",
    3 =&gt; "other thing",
  }
  NAMES.default = "default thing"
  </code></pre>
  
  <p>It feels like it ought to be faster to use <code>NAMES[id]</code> than <code>get_name(id)</code> - but is it?</p>