Created
March 21, 2017 15:53
-
-
Save fl0w/da347390d6135eb89bf74b0a186e176f to your computer and use it in GitHub Desktop.
This file contains 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 v8 = require('v8-natives') | |
const Benchmark = require('benchmark') | |
const suite = new Benchmark.Suite() | |
const MixinOne = (base) => class extends base {} | |
const MixinTwo = (base) => class extends base {} | |
const MixinThree = (base) => class extends base {} | |
const MixinFour = (base) => class extends base {} | |
const MixinFive = (base) => class extends base {} | |
class Base { | |
foo () { | |
return Math.random() | |
} | |
} | |
class MyModel extends Base {} | |
class MyModelOne extends MixinOne(Base) {} | |
class MyModelTwo extends MixinTwo(MixinOne(Base)) {} | |
class MyModelThree extends MixinThree(MixinTwo(MixinOne(Base))) {} | |
class MyModelFour extends MixinFour(MixinThree(MixinTwo(MixinOne(Base)))) {} | |
class MyModelFive extends MixinFive(MixinFour(MixinThree(MixinTwo(MixinOne(Base))))) {} | |
const n = 100000 | |
suite.add('Just Base', function () { | |
let bar = 0 | |
for (let i = 0; i < n; i++) | |
bar = bar + (new Base().foo()) | |
return bar | |
}).add('0 mixin (extend Base)', function () { | |
let bar = 0 | |
for (let i = 0; i < n; i++) | |
bar = bar + (new MyModel().foo()) | |
return bar | |
}).add('1 mixin', function () { | |
let bar = 0 | |
for (let i = 0; i < n; i++) | |
bar = bar + (new MyModelOne().foo()) | |
return bar | |
}).add('2 mixin', function () { | |
let bar = 0 | |
for (let i = 0; i < n; i++) | |
bar = bar + (new MyModelTwo().foo()) | |
return bar | |
}).add('3 mixin', function () { | |
let bar = 0 | |
for (let i = 0; i < n; i++) | |
bar = bar + (new MyModelThree().foo()) | |
return bar | |
}).add('4 mixin', function () { | |
let bar = 0 | |
for (let i = 0; i < n; i++) | |
bar = bar + (new MyModelFour().foo()) | |
return bar | |
}).add('5 mixin', function () { | |
let bar = 0 | |
for (let i = 0; i < n; i++) | |
bar = bar + (new MyModelFive().foo()) | |
return bar | |
}).on('complete', function() { | |
console.log('Fastest is ' + this.filter('fastest').map('name')); | |
}).on('cycle', function(event) { | |
console.log(String(event.target)); | |
}).run({ 'async': true }) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment