Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<h1>Test case 1: <code>a</code> and <code>b</code> both global, no embedding.</h1> <pre><code>$ cat junk.lua ; time lua junk.lua function a(n) return n + 1 end function b(n) return a(n) end for c = 1, 10000000 do b(c) end real 0m1.743s user 0m1.740s sys 0m0.000s </code></pre> <p>User time: <strong>1.74s</strong>.</p> <h1>Test case 2: <code>a</code> local, <code>b</code> global, no embedding.</h1> <pre><code>local function a(n) return n + 1 end function b(n) return a(n) end for c = 1, 10000000 do b(c) end real 0m1.388s user 0m1.390s sys 0m0.000s </code></pre> <p>User time <strong>1.39s</strong>.</p> <h1>Test case 3: <code>a</code> and <code>b</code> both local, no embedding.</h1> <pre><code>$ cat junk.lua ; time lua junk.lua local function a(n) return n + 1 end local function b(n) return a(n) end for c = 1, 10000000 do b(c) end real 0m1.194s user 0m1.200s sys 0m0.000s </code></pre> <p>User time <strong>1.2s</strong>.</p> <h1>Test case 4: <code>a</code> embedded in <code>b</code>, <code>a</code> global, <code>b</code> local.</h1> <pre><code>$ cat junk.lua ; time lua junk.lua local function b(n) function a(n) return n + 1 end return a(n) end for c = 1, 10000000 do b(c) end real 0m2.804s user 0m2.790s sys 0m0.000s </code></pre> <p>User time: <strong>2.79s</strong>. (!)</p> <h1>Test case 5: <code>a</code> embedded in <code>b</code>, both local.</h1> <pre><code>$ cat junk.lua ; time lua junk.lua local function b(n) local function a(n) return n + 1 end return a(n) end for c = 1, 10000000 do b(c) end real 0m2.540s user 0m2.530s sys 0m0.000s </code></pre> <p>User time: <strong>2.53s</strong>.</p> <h1>Result summary:</h1> <ol> <li>It's easy to write tests to confirm or deny intuitions about performance. You should probably do this instead of relying on crowd-sourcing the answer. (The crowd is often wrong, you see.)</li> <li>Making functions local instead of global has a significant positive impact on function call overhead. (About 30% better in this set of test cases when both functions were local.)</li> <li>Embedding a function in another function has a serious negative impact on function call overhead. (About 110% worse in this set of test cases when both functions were local.)</li> <li>Did I mention that testing is probably a good idea in lieux of trusting the crowd?</li> </ol>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload