Last active
January 18, 2018 00:03
-
-
Save suguru03/0248190cd56fb3ba406979f34802a70c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class MyArray extends Array {} |
This file contains hidden or 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
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