title: Why error() works faster then assert() in Lua?
body: <p>Assertion of condition is well known way to design application in <em>strategic way</em>. You could be completely sure that your code will work correctly a day after release, but also when other dev in your team will change this code.</p>
  
  <p>There are 2 common ways to put assertion in Lua code:</p>
  
  <pre><code>assert(1 &gt; 0, "Assert that math works")
  </code></pre>
  
  <pre><code>if 1 &lt;= 0 then
      error("Assert that math doesn't work")
  end
  </code></pre>
  
  <p>I would expect this thing similar from performance point of view.
  Consider it only matter of style. But it happens to be not true.</p>
  
  <p>assert works longer on my machine:</p>
  
  <pre><code>function with_assert()
      for i=1,100000 do 
          assert(1 &lt; 0, 'Assert')
      end
  end
  
  function with_error()
      for i=1,100000 do 
          if 1 &gt; 0 then
              error('Error')
          end
      end
  end
  
  local t = os.clock()
  pcall(with_assert)
  print(os.clock() - t)
  
  t = os.clock()
  pcall(with_error)
  print(os.clock() - t)
  </code></pre>
  
  <blockquote>
    <p>>> 3.1999999999999e-05</p>
    
    <p>>> 1.5e-05</p>
  </blockquote>
  
  <p>Why does it happen?</p>