Skip to content

Instantly share code, notes, and snippets.

@suguru03
Last active January 18, 2018 00:03
Show Gist options
  • Save suguru03/0248190cd56fb3ba406979f34802a70c to your computer and use it in GitHub Desktop.
Save suguru03/0248190cd56fb3ba406979f34802a70c to your computer and use it in GitHub Desktop.
class MyArray extends Array {}
const len = 10000000;
let str = '';
for (let i = 0; i < len; i++) {
str += 97 + i % 26;
}
function checkArray(input) {
let i = -1;
const l = input.length;
const array = [];
while (++i < l) {
array.push(input[i]);
}
array.slice(0);
}
function check(title) {
const start = Date.now();
checkArray(str);
const end = Date.now() - start;
console.log(`${title}: ${end}ms`);
}
// Typescript generates this function
function __extends(d, b) {
Object.setPrototypeOf(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
}
function MyArray() {
}
check('before extend');
__extends(MyArray, Array);
check('after extend');
// Node v8.9.4
// before: 1946
// after: 4277
// Chrome v63.0.3239.132
// before: 1861
// after: 4844
// Firefox 57.0.4
// before: 1338
// after: 1046
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment