Created
November 15, 2012 20:50
-
-
Save Talleyran/4081173 to your computer and use it in GitHub Desktop.
js test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let t, | |
F,F2,F3,F4, | |
G,G2,G3,G4, | |
E,E2,E3,E4, | |
obj,obj2,obj3,obj4,obj5,obj6,obj7,obj8 | |
F = function(){ this.a = 1 } | |
F.prototype.setA = function(v){ this.a = v } | |
F2 = function(){ this.a = 1; this.b = 1 } | |
F2.prototype = new F | |
F2.prototype.setB = function(v){ this.b = v } | |
F3 = function(){ this.a = 1; this.b = 1; this.c = 1 } | |
F3.prototype = new F2 | |
F2.prototype.setC = function(v){ this.c = v } | |
F4 = function(){ this.a = 1; this.b = 1; this.c = 1; this.d = 1 } | |
F4.prototype = new F3 | |
F2.prototype.setD = function(v){ this.d = v } | |
obj = new F; obj2 = new F2; obj3 = new F3; obj4 = new F4; | |
obj5 = new F; obj6 = new F2; obj7 = new F3; obj8 = new F4; | |
t = (new Date).getTime() | |
for(let i=0; i<100000; i++){ | |
obj.setA(i) | |
obj5.setA(i) | |
} | |
console.log((new Date).getTime() - t + 'ms') | |
t = (new Date).getTime() | |
for(let i=0; i<100000; i++){ | |
obj2.setA(i) | |
obj6.setB(i) | |
} | |
console.log((new Date).getTime() - t + 'ms') | |
t = (new Date).getTime() | |
for(let i=0; i<100000; i++){ | |
obj3.setA(i) | |
obj7.setC(i) | |
} | |
console.log((new Date).getTime() - t + 'ms') | |
t = (new Date).getTime() | |
for(let i=0; i<100000; i++){ | |
obj4.setA(i) | |
obj8.setD(i) | |
} | |
console.log((new Date).getTime() - t + 'ms') | |
console.log ('-----') | |
G = function(){ return { a: 1, setA: function(v){ this.a = v } } } | |
G2 = function(){ let t = G(); t.b = 1; t.setB = function(v){ this.b = v }; return t } | |
G3 = function(){ let t = G2(); t.c = 1; t.setC = function(v){ this.c = v }; return t } | |
G4 = function(){ let t = G3(); t.d = 1; t.setD = function(v){ this.d = v }; return t } | |
obj = G(); obj2 = G2(); obj3 = G3(); obj4 = G4(); | |
obj5 = G(); obj6 = G2(); obj7 = G3(); obj8 = G4(); | |
t = (new Date).getTime() | |
for(let i=0; i<100000; i++){ | |
obj.setA(i) | |
obj5.setA(i) | |
} | |
console.log((new Date).getTime() - t + 'ms') | |
t = (new Date).getTime() | |
for(let i=0; i<100000; i++){ | |
obj2.setA(i) | |
obj6.setB(i) | |
} | |
console.log((new Date).getTime() - t + 'ms') | |
t = (new Date).getTime() | |
for(let i=0; i<100000; i++){ | |
obj3.setA(i) | |
obj7.setC(i) | |
} | |
console.log((new Date).getTime() - t + 'ms') | |
t = (new Date).getTime() | |
for(let i=0; i<100000; i++){ | |
obj4.setA(i) | |
obj8.setD(i) | |
} | |
console.log((new Date).getTime() - t + 'ms') | |
console.log ('-----') | |
let setA = function(v){ this.a = v } | |
let setB = function(v){ this.b = v } | |
let setC = function(v){ this.c = v } | |
let setD = function(v){ this.d = v } | |
E = function(){ return { a: 1, setA: setA } } | |
E2 = function(){ let t = E(); t.b = 1; t.setB = setB; return t } | |
E3 = function(){ let t = E2(); t.c = 1; t.setC = setC; return t } | |
E4 = function(){ let t = E3(); t.d = 1; t.setD = setD; return t } | |
obj = E(); obj2 = E2(); obj3 = E3(); obj4 = E4(); | |
obj5 = E(); obj6 = E2(); obj7 = E3(); obj8 = E4(); | |
t = (new Date).getTime() | |
for(let i=0; i<100000; i++){ | |
obj.setA(i) | |
obj5.setA(i) | |
} | |
console.log((new Date).getTime() - t + 'ms') | |
t = (new Date).getTime() | |
for(let i=0; i<100000; i++){ | |
obj2.setA(i) | |
obj6.setB(i) | |
} | |
console.log((new Date).getTime() - t + 'ms') | |
t = (new Date).getTime() | |
for(let i=0; i<100000; i++){ | |
obj3.setA(i) | |
obj7.setC(i) | |
} | |
console.log((new Date).getTime() - t + 'ms') | |
t = (new Date).getTime() | |
for(let i=0; i<100000; i++){ | |
obj4.setA(i) | |
obj8.setD(i) | |
} | |
console.log((new Date).getTime() - t + 'ms') | |
console.log ('-----') | |
t = (new Date).getTime() | |
for(let i=0; i<100000; i++){ | |
new F4 | |
} | |
console.log((new Date).getTime() - t + 'ms') | |
t = (new Date).getTime() | |
for(let i=0; i<100000; i++){ | |
G4() | |
} | |
console.log((new Date).getTime() - t + 'ms') | |
t = (new Date).getTime() | |
for(let i=0; i<100000; i++){ | |
E4() | |
} | |
console.log((new Date).getTime() - t + 'ms') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment