Script Preparation code:
x
 
function mkLazyTest(fn) {
  var thunk = fn, ran = false, value = null;
  return function() {
    if (!ran) {
      value = thunk();
      ran = true;
    }
    return value;
  };
}
function mkLazyCall(fn) {
  var thunk = fn;
  var get = function() {
    var value = thunk();
    get = function() { return value; };
    return value;
  };
  return function() { return get(); };
}
function cfn(v) { 
  return function() { return v; }
}
var fn = cfn(1);
var lz1 = mkLazyTest(fn);
var lz2 = mkLazyCall(fn);
var i = 0, iterations = 1000;
Tests:
  • Lazy with existence test

     
    for (i = 0; i < iterations ; i++) {
      lz1();
    }
  • Lazy with fetch call

     
    for (i = 0; i < iterations ; i++) {
      lz2();
    }
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    Lazy with existence test
    Lazy with fetch call

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 3 years ago)
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:92.0) Gecko/20100101 Firefox/92.0
Firefox 92 on Windows
View result in a separate tab
Test name Executions per second
Lazy with existence test 38811.3 Ops/sec
Lazy with fetch call 38988.2 Ops/sec