title: Why Javascript Eval is slower, when it shouldn't be
body: <p>So i'm trying to create my own JS framework just for my own pleasure (and probably then convert into usefullness) and I most of the time focus on generating JS dynamicly (since having higher level with JS as language-in-the-middle is bad idea, IMO)</p>
  
  <p>And I got into one trouble. I was trying to do following</p>
  
  <pre><code>var f = null;
  var converted = "f = function(){ &lt;do something here&gt;";
  for(var x in list)
   converted+=list[x];
  converted+="};";
  eval(converted);
  </code></pre>
  
  <p>So this pretty much writes constructed function to f, that I can later execute.</p>
  
  <p>But here's the catch - it runs slower, than if I just write code of f completely in file, which is very strange. Let me explain why it's strange to me: when you just run eval each time, Chrome precompiler (or whatever browser precompiler - chrome is what I target) can't cache-compile the code, because it expects, that it will change with each run. </p>
  
  <p>However, when you save this to a function, it creates a new VM machine file, because after you saved the function's code, you can't change it. So why, when I do such eval, it runs slower than normal execution? I mean after code was executed more than once. Why this should matter?</p>
  
  <p>PS: The method I had shown above, works faster that eval-ing each time. So I don't understand why stopwatches show time inbetween, again, ignoring first 1-10 calls</p>
  
  <p>PPS: Test case: <a href="http://jsperf.com/evaluated-function-vs-real-function/2" rel="nofollow">http://jsperf.com/evaluated-function-vs-real-function/2</a></p>