var Obj = (function () {
function Obj(a, b) {
this.a = a;
this.b = b;
}
;
Obj.prototype.c = function (v) {
return this.a + v;
};
Obj.prototype.d = function (v) {
return this.a + this.b + v;
};
return Obj;
}());
var obj = new Obj(1, 2);
var e = 1;
var e = obj.c(e) + obj.d(e + 1);
function makeObj(a, b) {
return {
c: function (v) {
return a + v;
},
d: function (v) {
return a + b + v;
}
};
}
var obj = makeObj(1, 2);
var e = 1;
var e = obj.c(e) + obj.d(e + 1);
function makeObj(_a, _b) {
var a = _a;
var b = _b;
return {
c: function (v) {
return a + v;
},
d: function (v) {
return a + b + v;
}
};
}
var obj = makeObj(1, 2);
var e = 1;
var e = obj.c(e) + obj.d(e + 1);
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
No fat arrow | |
With fat arrow | |
With fat arrow and let |
Test name | Executions per second |
---|---|
No fat arrow | 341502.0 Ops/sec |
With fat arrow | 77240144.0 Ops/sec |
With fat arrow and let | 78141984.0 Ops/sec |
Let's break down the provided benchmark and its test cases to understand what is being tested.
Benchmark Overview
The benchmark measures the performance difference between three approaches:
var makeObj = function(a, b) { ... }
)const makeObj = () => { ... }
)let
variablesTest Cases
There are three test cases:
c
and d
.let
variables to create the object.Options Compared
The benchmark is comparing the performance of these three approaches:
var
)() => { ... }
)let
variables (e.g., const [a, b] = ...; let a = _a; let b = _b; return { ... }
)Pros and Cons
Here's a brief summary of the pros and cons of each approach:
var
):let
Variables:Library and Syntax
The test cases use a combination of:
function makeObj(a, b) { ... }
)const makeObj = () => { ... }
)There are no libraries used in the provided benchmark.
Special JS Features or Syntax
The test cases utilize:
let
Variables: Introduced in ECMAScript 2015, these provide block scope and help reduce variable declarations.Alternatives
Other alternatives that could be used to measure performance differences in JavaScript functions include:
import
statements instead of require
.bind()
or call()
to create closures.Please note that the specific alternatives will depend on the use case and requirements of the benchmark.