Last active
August 29, 2015 14:20
-
-
Save trevnorris/0b7b208e420a4d8f7fc2 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
| 'use strict'; | |
| const ITER = 1e7; | |
| function Foo() { | |
| this.futz = this.constructor.futz; | |
| } | |
| Foo.futz = false; | |
| function Bar() { | |
| Foo.call(this); | |
| } | |
| Bar.__proto__ = Foo; | |
| Bar.prototype.__proto__ = Foo.prototype; | |
| let t = performance.now(); | |
| for (var i = 0; i < ITER; i++) { | |
| new Bar(); | |
| } | |
| t = performance.now() - t; | |
| print(((t * 1e6) / ITER).toFixed(1) + ' ns/op'); | |
| // 25 ns/op |
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
| 'use strict'; | |
| class Foo { | |
| constructor() { | |
| this.futz = this.constructor.futz; | |
| } | |
| } | |
| Foo.futz = false; | |
| class Bar extends Foo { | |
| constructor() { | |
| super(); | |
| } | |
| } | |
| let t = performance.now(); | |
| for (var i = 0; i < ITER; i++) { | |
| new Bar(); | |
| } | |
| t = performance.now() - t; | |
| print(((t * 1e6) / ITER).toFixed(1) + ' ns/op'); | |
| // 180 ns/op |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment