Skip to content

Instantly share code, notes, and snippets.

@ifraixedes ifraixedes/LICENSE
Created Feb 18, 2016

Embed
What would you like to do?
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE Version 2, December 2004
(http://www.wtfpl.net/about/)
Copyright (C) 2015 Ivan Fraixedes (https://ivan.fraixed.es)
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.
{
"main": "perf-test.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"license": "WTFPL",
"devDependencies": {
"benchmark": "^2.1.0",
"microtime": "^2.0.0"
}
}
'use strict';
let benchmark = require('benchmark');
let obj = {
execFe: function(a, b, c) {
return (function (a, b, c) {
return (a + b) * c;
}(a, b, c));
},
execAf: function(a, b, c) {
return ((a, b, c) => (a + b) * c)(a, b, c);
}
};
module.exports = obj;
let suite = new benchmark.Suite;
suite.add('arrow function', function () {
obj.execAf(5, 10, 60);
})
.add('normal function', function () {
obj.execFe(5, 10, 60);
})
.on('complete', function () {
this.forEach(b => {
console.log(`${b.name} -> mean: ${b.stats.mean}`);
});
let b = this[0];
let m = this[1];
let diff = b.stats.mean - m.stats.mean;
console.log(`${b.name} is ${(diff < 0) ? 'faster' : 'slower'} than ${m.name} by ${(diff < 0) ? -diff : diff} seconds`);
console.log(`Fastest is: ${this.filter('fastest').map('name')}`);
})
.run({ async: false });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.