Script Preparation code:
x
 
let scopeX = 0;
function Constructor(f) {
  return Object.setPrototypeOf(f, Constructor.prototype);
};
Constructor.prototype = {
  get x() {
    return scopeX;
  },
  y() {
    scopeX = scopeX + 1;
  }
};
Object.setPrototypeOf(Constructor, Function);
Object.setPrototypeOf(Constructor.prototype, Function.prototype);
var makeConstructor = name => new Constructor(({
  [name]() {
    return "My name is\n" + name;
  }
})[name]);
var aConstructor = makeConstructor("Chika-chika\nSlim Shady");
literalPrototype = {
  get x() {
    return scopeX;
  },
  y() {
    scopeX = scopeX + 1;
  }
};
Object.setPrototypeOf(literalPrototype, Function.prototype);
var makeLiteral = name => Object.setPrototypeOf(({
  [name]() {
    return "My name is\n" + name;
  }
})[name], literalPrototype);
var aLiteral = makeConstructor("Chika-chika\nSlim Shady");
Tests:
  • makeConstructor

     
    const aConstructor = makeConstructor("Chika-chika\nSlim Shady");
  • makeLiteral

     
    var aLiteral = makeConstructor("Chika-chika\nSlim Shady");
  • invoke aConstructor

     
    aConstructor();
  • invoke aLiteral

     
    aLiteral();
  • invoke prototype method aConstructor

     
    aConstructor.y()
  • invoke prototype method aLiteral

     
    aLiteral.y();
  • getter aConstructor

     
    const value = aConstructor.x;
  • getter aLiteral

     
    const value = aLiteral.x;
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    makeConstructor
    makeLiteral
    invoke aConstructor
    invoke aLiteral
    invoke prototype method aConstructor
    invoke prototype method aLiteral
    getter aConstructor
    getter aLiteral

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 4 years ago)
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36
Chrome 89 on Windows
View result in a separate tab
Test name Executions per second
makeConstructor 835984.8 Ops/sec
makeLiteral 873508.4 Ops/sec
invoke aConstructor 10111645.0 Ops/sec
invoke aLiteral 10260750.0 Ops/sec
invoke prototype method aConstructor 9628953.0 Ops/sec
invoke prototype method aLiteral 10018681.0 Ops/sec
getter aConstructor 10158993.0 Ops/sec
getter aLiteral 10195548.0 Ops/sec