Skip to content

Instantly share code, notes, and snippets.

@trevnorris
Last active August 29, 2015 14:20
Show Gist options
  • Select an option

  • Save trevnorris/0b7b208e420a4d8f7fc2 to your computer and use it in GitHub Desktop.

Select an option

Save trevnorris/0b7b208e420a4d8f7fc2 to your computer and use it in GitHub Desktop.
'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
'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