Add ability to benchmark things

This commit is contained in:
Aaron Jensen 2015-08-09 23:25:19 -07:00
parent b1701b09bd
commit 5c64c7fbf6
6 changed files with 110 additions and 1 deletions

View File

@ -6,6 +6,9 @@ module.exports = function createWebpackConfig(_options) {
var options = _options || {};
config = {
context: options.context,
entry: options.entry,
plugins: [
new webpack.optimize.OccurrenceOrderPlugin(),
],

View File

@ -20,7 +20,8 @@
],
"scripts": {
"test": "gulp",
"prepublish": "gulp prepublish"
"prepublish": "gulp prepublish",
"perf-server": "`npm bin`/webpack-dev-server --config perf/webpack.config.js --hot"
},
"license": "MIT",
"bugs": {
@ -33,9 +34,11 @@
"babel-core": "^5.5.0",
"babel-eslint": "^4.0.5",
"babel-loader": "^5.3.2",
"benchmark": "^1.0.0",
"chai": "^3.2.0",
"eslint": "^0.24.1",
"eslint-config-airbnb": "0.0.7",
"exports-loader": "^0.6.2",
"gulp": "^3.6.0",
"gulp-babel": "^5.1.0",
"gulp-eslint": "^0.15.0",
@ -54,6 +57,7 @@
"phantomjs": "^1.9.17",
"rimraf": "^2.4.2",
"webpack": "^1.10.5",
"webpack-dev-server": "^1.10.1",
"webpack-stream": "^2.1.0"
}
}

10
perf/.eslintrc Normal file
View File

@ -0,0 +1,10 @@
{
"extends": "../.eslintrc",
"rules": {
"new-cap": [2, {
"capIsNewExceptions": [
"Suite"
]
}],
}
}

14
perf/index.html Normal file
View File

@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<title>updeep perf</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div>Running tests...</div>
<div id='perf'></div>
<script src='/assets/perf.js'></script>
<div>Done!</div>
</body>
</html>

46
perf/index.js Normal file
View File

@ -0,0 +1,46 @@
const Benchmark = require('benchmark');
const u = require('../lib');
const _ = require('lodash');
const suite = Benchmark.Suite(); // eslint-disable
const add = (x, y) => x + y;
const fakeCurryAdd = x => y => x + y;
const curryAdd = _.curry(add);
const array = [0, 1, 2, 3, 4, 5];
suite
.add('regular function call', () => {
add(3, 4);
})
.add('fake curry', () => {
fakeCurryAdd(3)(4);
})
.add('curry full call', () => {
curryAdd(3, 4);
})
.add('curry partial call', () => {
curryAdd(3)(4);
})
.add('_.map', () => {
_.map(array, curryAdd(8));
})
.add('u.map', () => {
u.map(curryAdd(8), array);
})
.add('_.map no changes', () => {
_.map(array, x => x);
})
.add('u.map no changes', () => {
u.map(x => x, array);
})
.on('cycle', (event) => {
if (typeof document !== 'undefined') {
const el = document.getElementById('perf');
el.innerHTML = el.innerHTML + String(event.target) + '<br>';
}
})
.run({ async: true });

32
perf/webpack.config.js Normal file
View File

@ -0,0 +1,32 @@
'use strict'; /* eslint strict:0, no-var:0, func-names:0 */
var path = require('path');
var config = require('../createWebpackConfig')({
context: __dirname,
entry: [
'webpack/hot/dev-server',
'./index.js',
],
minify: false,
env: 'production',
});
config.output = {
path: path.join(__dirname, './build'),
publicPath: '/assets/',
filename: 'perf.js',
};
config.devServer = {
contentBase: __dirname,
noInfo: true,
hot: true,
inline: true,
};
config.module.noParse = [
/benchmark\.js$/,
];
module.exports = config;