Performance benchmarks are ran in node
This commit is contained in:
parent
73b2caa838
commit
c63801184f
11
.eslintrc.js
11
.eslintrc.js
@ -41,16 +41,7 @@ const config = {
|
|||||||
sourceType: 'module',
|
sourceType: 'module',
|
||||||
},
|
},
|
||||||
rules: {
|
rules: {
|
||||||
"no-unused-expressions": 0
|
"no-unused-expressions": 'off'
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
files: ['perf/**/*'],
|
|
||||||
env: {
|
|
||||||
browser: true
|
|
||||||
},
|
|
||||||
rules: {
|
|
||||||
'no-unused-vars': 'off',
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
"url": "https://github.com/substantial/updeep/issues"
|
"url": "https://github.com/substantial/updeep/issues"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
"benchmark": "NODE_ENV=production node --require \"@babel/register\" perf",
|
||||||
"build": "microbundle",
|
"build": "microbundle",
|
||||||
"dev": "microbundle watch",
|
"dev": "microbundle watch",
|
||||||
"dtslint": "dtslint --localTs node_modules/typescript/lib types",
|
"dtslint": "dtslint --localTs node_modules/typescript/lib types",
|
||||||
@ -51,6 +52,7 @@
|
|||||||
"@typescript-eslint/parser": "^2.26.0",
|
"@typescript-eslint/parser": "^2.26.0",
|
||||||
"benchmark": "^2.1.4",
|
"benchmark": "^2.1.4",
|
||||||
"chai": "^4.2.0",
|
"chai": "^4.2.0",
|
||||||
|
"chalk": "^4.0.0",
|
||||||
"dtslint": "^3.4.1",
|
"dtslint": "^3.4.1",
|
||||||
"eslint": "^6.8.0",
|
"eslint": "^6.8.0",
|
||||||
"eslint-config-prettier": "^6.10.1",
|
"eslint-config-prettier": "^6.10.1",
|
||||||
@ -62,6 +64,7 @@
|
|||||||
"microbundle": "^0.11.0",
|
"microbundle": "^0.11.0",
|
||||||
"mocha": "^7.0.0",
|
"mocha": "^7.0.0",
|
||||||
"prettier": "^2.0.2",
|
"prettier": "^2.0.2",
|
||||||
|
"table": "^5.4.6",
|
||||||
"typescript": "^3.6.3"
|
"typescript": "^3.6.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
14
perf/.eslintrc.js
Normal file
14
perf/.eslintrc.js
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
module.exports = {
|
||||||
|
extends: require.resolve("../.eslintrc.js"),
|
||||||
|
env: {
|
||||||
|
node: true,
|
||||||
|
es6: true,
|
||||||
|
},
|
||||||
|
parserOptions: {
|
||||||
|
sourceType: 'module',
|
||||||
|
},
|
||||||
|
rules: {
|
||||||
|
'no-unused-vars': 'off',
|
||||||
|
'@typescript-eslint/no-unused-vars': 'off'
|
||||||
|
}
|
||||||
|
}
|
@ -1,14 +0,0 @@
|
|||||||
<!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="/index.js"></script>
|
|
||||||
<p>Done!</p>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
@ -1,8 +1,10 @@
|
|||||||
const Benchmark = require('benchmark')
|
import Benchmark from 'benchmark'
|
||||||
|
import {table} from 'table'
|
||||||
|
import chalk from 'chalk'
|
||||||
|
|
||||||
const _ = require('lodash')
|
import _ from 'lodash'
|
||||||
const u = require('../lib')
|
import u from '../dist/index.umd.js'
|
||||||
const { curry2, curry4 } = require('../lib/util/curry')
|
import {curry2, curry4 } from '../lib/util/curry'
|
||||||
|
|
||||||
const add4 = (a, b, c, d) => a + b + c + d
|
const add4 = (a, b, c, d) => a + b + c + d
|
||||||
const add2 = (a, b) => a + b
|
const add2 = (a, b) => a + b
|
||||||
@ -16,33 +18,31 @@ const updeepCurryAdd4 = curry4(add4)
|
|||||||
const array = [0, 1, 2, 3, 4, 5]
|
const array = [0, 1, 2, 3, 4, 5]
|
||||||
// const doUpdate = u(x => x + 1);
|
// const doUpdate = u(x => x + 1);
|
||||||
|
|
||||||
function log(str) {
|
|
||||||
if (typeof document !== 'undefined') {
|
const log = console.log
|
||||||
console.log(str)
|
|
||||||
const el = document.getElementById('perf')
|
|
||||||
el.innerHTML += str
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function createSuite(suiteName, tests) {
|
function createSuite(suiteName, tests) {
|
||||||
const suite = Benchmark.Suite() // eslint-disable
|
const results = []
|
||||||
|
|
||||||
return () => {
|
const suite = Benchmark.Suite({
|
||||||
log(`<h2>${suiteName}</h2><ul>`)
|
onCycle: (event) => {
|
||||||
|
results.push(event.target)
|
||||||
|
},
|
||||||
|
onError: (event) => {
|
||||||
|
console.error(event)
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
_.each(tests, (fn, testName) => {
|
_.each(tests, (fn, testName) => {
|
||||||
suite.add(testName, fn)
|
suite.add(testName, fn)
|
||||||
})
|
})
|
||||||
|
|
||||||
suite
|
return () => new Promise((resolve, reject) => {
|
||||||
.on('cycle', (event) => {
|
suite.on('complete', () => resolve({
|
||||||
log(`<li>${String(event.target)}</li>`)
|
suiteName,
|
||||||
|
results,
|
||||||
|
})).on('error', reject).run({ async: true})
|
||||||
})
|
})
|
||||||
.on('complete', () => {
|
|
||||||
log('</ul>')
|
|
||||||
})
|
|
||||||
.run({ async: true })
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const curryVsLodash = createSuite('Curry', {
|
const curryVsLodash = createSuite('Curry', {
|
||||||
@ -80,6 +80,25 @@ const applyVsDestructure = createSuite('apply vs destructure', {
|
|||||||
destructure: () => fnDestructure(1, 2, 3, 4, 5),
|
destructure: () => fnDestructure(1, 2, 3, 4, 5),
|
||||||
})
|
})
|
||||||
|
|
||||||
curryVsLodash()
|
const printSuiteResults = (suiteResults) => {
|
||||||
mapVsLodash()
|
const HEADERS = ['Suite Name', 'Results (fastest first)'].map(s => chalk.bold(s))
|
||||||
// applyVsDestructure();
|
|
||||||
|
const data = suiteResults.reduce((acc, {suiteName, results}) => {
|
||||||
|
const row = [
|
||||||
|
chalk.cyan(suiteName),
|
||||||
|
results.sort((a, b) => -a.compare(b)).map(String).join('\n'),
|
||||||
|
]
|
||||||
|
|
||||||
|
acc.push(row)
|
||||||
|
return acc
|
||||||
|
}, [HEADERS])
|
||||||
|
|
||||||
|
log(table(data))
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Promise.all([
|
||||||
|
curryVsLodash(),
|
||||||
|
mapVsLodash(),
|
||||||
|
// applyVsDestructure(),
|
||||||
|
]).then(printSuiteResults)
|
||||||
|
10
yarn.lock
10
yarn.lock
@ -1392,6 +1392,14 @@ chalk@^3.0.0:
|
|||||||
ansi-styles "^4.1.0"
|
ansi-styles "^4.1.0"
|
||||||
supports-color "^7.1.0"
|
supports-color "^7.1.0"
|
||||||
|
|
||||||
|
chalk@^4.0.0:
|
||||||
|
version "4.0.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/chalk/-/chalk-4.0.0.tgz#6e98081ed2d17faab615eb52ac66ec1fe6209e72"
|
||||||
|
integrity sha512-N9oWFcegS0sFr9oh1oz2d7Npos6vNoWW9HvtCg5N1KRFpUhaAhvTv5Y58g880fZaEYSNm3qDz8SU1UrGvp+n7A==
|
||||||
|
dependencies:
|
||||||
|
ansi-styles "^4.1.0"
|
||||||
|
supports-color "^7.1.0"
|
||||||
|
|
||||||
chardet@^0.7.0:
|
chardet@^0.7.0:
|
||||||
version "0.7.0"
|
version "0.7.0"
|
||||||
resolved "https://registry.yarnpkg.com/chardet/-/chardet-0.7.0.tgz#90094849f0937f2eedc2425d0d28a9e5f0cbad9e"
|
resolved "https://registry.yarnpkg.com/chardet/-/chardet-0.7.0.tgz#90094849f0937f2eedc2425d0d28a9e5f0cbad9e"
|
||||||
@ -6033,7 +6041,7 @@ symbol-observable@^1.1.0:
|
|||||||
resolved "https://registry.yarnpkg.com/symbol-observable/-/symbol-observable-1.2.0.tgz#c22688aed4eab3cdc2dfeacbb561660560a00804"
|
resolved "https://registry.yarnpkg.com/symbol-observable/-/symbol-observable-1.2.0.tgz#c22688aed4eab3cdc2dfeacbb561660560a00804"
|
||||||
integrity sha512-e900nM8RRtGhlV36KGEU9k65K3mPb1WV70OdjfxlG2EAuM1noi/E/BaW/uMhL7bPEssK8QV57vN3esixjUvcXQ==
|
integrity sha512-e900nM8RRtGhlV36KGEU9k65K3mPb1WV70OdjfxlG2EAuM1noi/E/BaW/uMhL7bPEssK8QV57vN3esixjUvcXQ==
|
||||||
|
|
||||||
table@^5.2.3:
|
table@^5.2.3, table@^5.4.6:
|
||||||
version "5.4.6"
|
version "5.4.6"
|
||||||
resolved "https://registry.yarnpkg.com/table/-/table-5.4.6.tgz#1292d19500ce3f86053b05f0e8e7e4a3bb21079e"
|
resolved "https://registry.yarnpkg.com/table/-/table-5.4.6.tgz#1292d19500ce3f86053b05f0e8e7e4a3bb21079e"
|
||||||
integrity sha512-wmEc8m4fjnob4gt5riFRtTu/6+4rSe12TpAELNSqHMfF3IqnA+CH37USM6/YR3qRZv7e56kAEAtd6nKZaxe0Ug==
|
integrity sha512-wmEc8m4fjnob4gt5riFRtTu/6+4rSe12TpAELNSqHMfF3IqnA+CH37USM6/YR3qRZv7e56kAEAtd6nKZaxe0Ug==
|
||||||
|
Loading…
Reference in New Issue
Block a user