Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save faiwer/fb5b0b4bc522c21fc128 to your computer and use it in GitHub Desktop.
Save faiwer/fb5b0b4bc522c21fc128 to your computer and use it in GitHub Desktop.
(function()
{
"use strict";
let limit = 100000;
class A1
{
a1(){ return '1'; }
b1(){ return 1; }
c1(){ return '1'; }
d1(){ return 1; }
}
class A2 extends A1
{
a2(){ return '2'; }
b2(){ return 2; }
c2(){ return '2'; }
d2(){ return 2; }
}
class A3 extends A2
{
a3(){ return '3'; }
b3(){ return 3; }
c3(){ return '3'; }
d3(){ return 3; }
}
class A4 extends A3
{
a4(){ return '4'; }
b4(){ return 4; }
c4(){ return '4'; }
d4(){ return 4; }
}
class A5 extends A4
{
a5(){ return '5'; }
b5(){ return 5; }
c5(){ return '5'; }
d5(){ return 5; }
}
class A6 extends A5
{
a6(){ return '6'; }
b6(){ return 6; }
c6(){ return '6'; }
d6(){ return 6; }
}
class A7 extends A6
{
a7(){ return '7'; }
b7(){ return 7; }
c7(){ return '7'; }
d7(){ return 7; }
}
class A8 extends A7
{
a8(){ return '8'; }
b8(){ return 8; }
c8(){ return '8'; }
d8(){ return 8; }
}
class A9 extends A8
{
a9(){ return '9'; }
b9(){ return 9; }
c9(){ return '9'; }
d9(){ return 9; }
}
class A10 extends A9
{
a10(){ return '10'; }
b10(){ return 10; }
c10(){ return '10'; }
d10(){ return 10; }
}
class A11 extends A10
{
a11(){ return '11'; }
b11(){ return 11; }
c11(){ return '11'; }
d11(){ return 11; }
}
class A12 extends A11
{
a12(){ return '12'; }
b12(){ return 12; }
c12(){ return '12'; }
d12(){ return 12; }
}
class A13 extends A12
{
a13(){ return '13'; }
b13(){ return 13; }
c13(){ return '13'; }
d13(){ return 13; }
}
class A14 extends A13
{
a14(){ return '14'; }
b14(){ return 14; }
c14(){ return '14'; }
d14(){ return 14; }
}
class A15 extends A14
{
a15(){ return '15'; }
b15(){ return 15; }
c15(){ return '15'; }
d15(){ return 15; }
}
class A16 extends A15
{
a16(){ return '16'; }
b16(){ return 16; }
c16(){ return '16'; }
d16(){ return 16; }
}
class A17 extends A16
{
a1(){ return '1'; }
b1(){ return 1; }
c1(){ return '1'; }
d1(){ return 1; }
a16(){ return '16'; }
b16(){ return 16; }
c16(){ return '16'; }
d16(){ return 16; }
a17(){ return '17'; }
b17(){ return 17; }
c17(){ return '17'; }
d17(){ return 17; }
}
console.time('proto');
let a = new A17();
let s = '', n = 0;
for(let i = 0; i < limit; ++ i)
{
s += a.a1() +a.c1();
n += a.b1() + a.d1();
}
console.log( s.length, n );
console.timeEnd('proto');
class B
{
a1(){ return 'a'; }
b1(){ return 1; }
c1(){ return 'c'; }
d1(){ return 1; }
a2(){ return 'a'; }
b2(){ return 2; }
c2(){ return 'c'; }
d2(){ return 2; }
a3(){ return 'a'; }
b3(){ return 3; }
c3(){ return 'c'; }
d3(){ return 3; }
a4(){ return 'a'; }
b4(){ return 4; }
c4(){ return 'c'; }
d4(){ return 4; }
a5(){ return 'a'; }
b5(){ return 5; }
c5(){ return 'c'; }
d5(){ return 5; }
a6(){ return 'a'; }
b6(){ return 6; }
c6(){ return 'c'; }
d6(){ return 6; }
a7(){ return 'a'; }
b7(){ return 7; }
c7(){ return 'c'; }
d7(){ return 7; }
a8(){ return 'a'; }
b8(){ return 8; }
c8(){ return 'c'; }
d8(){ return 8; }
a9(){ return 'a'; }
b9(){ return 9; }
c9(){ return 'c'; }
d9(){ return 9; }
a10(){ return 'a'; }
b10(){ return 10; }
c10(){ return 'c'; }
d10(){ return 10; }
a11(){ return 'a'; }
b11(){ return 11; }
c11(){ return 'c'; }
d11(){ return 11; }
a12(){ return 'a'; }
b12(){ return 12; }
c12(){ return 'c'; }
d12(){ return 12; }
a13(){ return 'a'; }
b13(){ return 13; }
c13(){ return 'c'; }
d13(){ return 13; }
a14(){ return 'a'; }
b14(){ return 14; }
c14(){ return 'c'; }
d14(){ return 14; }
a15(){ return 'a'; }
b15(){ return 15; }
c15(){ return 'c'; }
d15(){ return 15; }
a16(){ return 'a'; }
b16(){ return 16; }
c16(){ return 'c'; }
d16(){ return 16; }
a17(){ return 'a'; }
b17(){ return 17; }
c17(){ return 'c'; }
d17(){ return 17; }
}
console.time('plain');
let b = new B();
s = '', n = 0;
for(let i = 0; i < limit; ++ i)
{
s += b.a1() + b.c1();
n += b.b1() + b.d1();
}
console.log( s.length, n );
console.timeEnd('plain');
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment