Run details:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36
Chrome 128
Windows
Desktop
4 months ago
Test name Executions per second
global add 223020.9 Ops/sec
inline add 194316.7 Ops/sec
global add 2 261134.1 Ops/sec
inline add 2 194070.9 Ops/sec
Tests:
  • global add

    x
     
    function addGlobal(a, b) {
      return a + b;
    }
    function myFunc(num) {
      return addGlobal(num, num+1);
    }
    for (let i = 0; i < 10000; i++) {
      myFunc(i);
    }
  • inline add

     
    function myFunc(num) {
      function addInline(a, b) {
        return a + b;
      }
      return addInline(num, num+1);
    }
    for (let i = 0; i < 10000; i++) {
      myFunc(i);
    }
  • global add 2

     
    // same as first one, just to ensure benchmarks are valid
    function addGlobal(a, b) {
      return a + b;
    }
    function myFunc(num) {
      return addGlobal(num, num+1);
    }
    for (let i = 0; i < 10000; i++) {
      myFunc(i);
    }
  • inline add 2

     
    function myFunc(num) {
      function addInline(a, b) {
        return a + b;
      }
      return addInline(num, num+1);
    }
    for (let i = 0; i < 10000; i++) {
      myFunc(i);
    }