Beruflich Dokumente
Kultur Dokumente
vs ES5 Object.create
JS
/* --------------------------
* Snippet 1
* Custom parent and child ES6 classes and using extends
* ----------------------------*/
function testClass(N){
class Parent{};
class X extends Parent {}
for(var i=0; i<N;i++){
new X();
}
}
testClass(1e6);
/* --------------------------
* Snippet 2
* Custom parent and child ES5 methods and using Object.crea
* for inheritance
* ----------------------------*/
function testPrototypes(N){
function Parent(){}
function X(){}
X.prototype = Object.create(Parent.prototype);
for(var i=0; i<N;i++){
new X();
}
}
testPrototypes(1e6);
/* --------------------------
* Snippet 3
* Built-in parent class and custom ES6 class using extends
* ----------------------------*/
function testClass(N){
class X extends Date{};
for(var i=0; i<N;i++){
new X();
}
}
testClass(1e6);
/* --------------------------
* Snippet 4
* Built-in parent class and custom child method using Objec
* ---------------------------- */
function testPrototypes(N){
function X(){}
X.prototype = Object.create(Date.prototype);
for(var i=0; i<N;i++){
new X();
}
}
testPrototypes(1e6);
Result
I am using jsperf.com for running the performance test
of above snippets. You can refer to it here for the below
ndings:
Show Comments