title: Encapsulation severely hurts performance?
body: <p>I know this question is kind of stupid, maybe it's a just a part of writing code but it seems defining simple functions can really hurt performance severely... I've tried this simple test:</p>
  
  <pre><code>def make_legal_foo_string(x):
      return "This is a foo string: " + str(x)
  
  def sum_up_to(x):
      return x*(x+1)/2
  
  def foo(x):
      return [make_legal_foo_string(x),sum_up_to(x),x+1]
  
  def bar(x):
      return ''.join([str(foo(x))," -- bar !! "])
  </code></pre>
  
  <p>it's very good style and makes code clear but it can be three times as slow as just writing it literally. It's inescapable for functions that can have side effects but it's actually almost trivial to define some functions that just should literally be replaced with lines of code every time they appear, translate the source code into that and only then compile. Same I think for magic numbers, it doesn't take a lot of time to read from memory but if they're not supposed to be changed then why not just replace every instance of 'magic' with a literal before the code compiles?</p>