Add ability to benchmark things
This commit is contained in:
parent
b1701b09bd
commit
5c64c7fbf6
@ -6,6 +6,9 @@ module.exports = function createWebpackConfig(_options) {
|
||||
var options = _options || {};
|
||||
|
||||
config = {
|
||||
context: options.context,
|
||||
entry: options.entry,
|
||||
|
||||
plugins: [
|
||||
new webpack.optimize.OccurrenceOrderPlugin(),
|
||||
],
|
||||
|
@ -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
10
perf/.eslintrc
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"extends": "../.eslintrc",
|
||||
"rules": {
|
||||
"new-cap": [2, {
|
||||
"capIsNewExceptions": [
|
||||
"Suite"
|
||||
]
|
||||
}],
|
||||
}
|
||||
}
|
14
perf/index.html
Normal file
14
perf/index.html
Normal 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
46
perf/index.js
Normal 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
32
perf/webpack.config.js
Normal 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;
|
Loading…
Reference in New Issue
Block a user