Created
March 21, 2017 14:02
-
-
Save fl0w/932fd6dc2ef1c2964fdcb563f9a18479 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 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 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))))) {} | |
// v8.neverOptimizeFunction(Base) | |
// v8.neverOptimizeFunction(MyModelOne) | |
// v8.neverOptimizeFunction(MyModelTwo) | |
// v8.neverOptimizeFunction(MyModelThree) | |
// v8.neverOptimizeFunction(MyModelFour) | |
// v8.neverOptimizeFunction(MixinOne) | |
// v8.neverOptimizeFunction(MixinTwo) | |
// v8.neverOptimizeFunction(MixinThree) | |
// v8.neverOptimizeFunction(MixinFour) | |
// v8.neverOptimizeFunction(constructOne) | |
// v8.neverOptimizeFunction(constructTwo) | |
// v8.neverOptimizeFunction(constructThree) | |
// v8.neverOptimizeFunction(constructFour) | |
// v8.neverOptimizeFunction(constructFive) | |
// | |
// function constructOne () { | |
// return (new MyModelOne().foo()) | |
// } | |
// function constructTwo () { | |
// return (new MyModelTwo().foo()) | |
// } | |
// function constructThree () { | |
// return (new MyModelThree().foo()) | |
// } | |
// function constructFour () { | |
// return (new MyModelFour().foo()) | |
// } | |
// function constructFive () { | |
// return (new MyModelFive().foo()) | |
// } | |
const n = 100000 | |
suite.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