Perf directory is added but not working yet
This commit is contained in:
parent
8335e227b1
commit
8dac85756c
11
.eslintrc.js
11
.eslintrc.js
@ -44,6 +44,15 @@ const config = {
|
||||
"no-unused-expressions": 0
|
||||
}
|
||||
},
|
||||
{
|
||||
files: ['perf/**/*'],
|
||||
env: {
|
||||
browser: true
|
||||
},
|
||||
rules: {
|
||||
'no-unused-vars': 'off',
|
||||
}
|
||||
},
|
||||
{
|
||||
files: ['**/*.@(ts|tsx)'],
|
||||
parser: '@typescript-eslint/parser',
|
||||
@ -52,8 +61,6 @@ const config = {
|
||||
sourceType: 'module',
|
||||
},
|
||||
rules: {
|
||||
'no-undef': 'off',
|
||||
'no-unused-vars': 'off',
|
||||
'@typescript-eslint/class-name-casing': 'error',
|
||||
'@typescript-eslint/consistent-type-assertions': 'error',
|
||||
'@typescript-eslint/no-empty-interface': 'error',
|
||||
|
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="/index.js"></script>
|
||||
<p>Done!</p>
|
||||
</body>
|
||||
</html>
|
85
perf/index.js
Normal file
85
perf/index.js
Normal file
@ -0,0 +1,85 @@
|
||||
const Benchmark = require('benchmark')
|
||||
|
||||
const _ = require('lodash')
|
||||
const u = require('../lib')
|
||||
const { curry2, curry4 } = require('../lib/util/curry')
|
||||
|
||||
const add4 = (a, b, c, d) => a + b + c + d
|
||||
const add2 = (a, b) => a + b
|
||||
const fakeCurryAdd = (x) => (y) => x + y
|
||||
const lodashCurryAdd2 = _.curry(add2)
|
||||
const updeepCurryAdd2 = curry2(add2)
|
||||
const lodashCurryAdd4 = _.curry(add4)
|
||||
const updeepCurryAdd4 = curry4(add4)
|
||||
// const updeepCurryBig = curry.curryBig(add);
|
||||
|
||||
const array = [0, 1, 2, 3, 4, 5]
|
||||
// const doUpdate = u(x => x + 1);
|
||||
|
||||
function log(str) {
|
||||
if (typeof document !== 'undefined') {
|
||||
console.log(str)
|
||||
const el = document.getElementById('perf')
|
||||
el.innerHTML += str
|
||||
}
|
||||
}
|
||||
|
||||
function createSuite(suiteName, tests) {
|
||||
const suite = Benchmark.Suite() // eslint-disable
|
||||
|
||||
return () => {
|
||||
log(`<h2>${suiteName}</h2><ul>`)
|
||||
|
||||
_.each(tests, (fn, testName) => {
|
||||
suite.add(testName, fn)
|
||||
})
|
||||
|
||||
suite
|
||||
.on('cycle', (event) => {
|
||||
log(`<li>${String(event.target)}</li>`)
|
||||
})
|
||||
.on('complete', () => {
|
||||
log('</ul>')
|
||||
})
|
||||
.run({ async: true })
|
||||
}
|
||||
}
|
||||
|
||||
const curryVsLodash = createSuite('Curry', {
|
||||
'updeep curry': () => {
|
||||
updeepCurryAdd4(3)(4)(5)(6)
|
||||
updeepCurryAdd4(3, 4, 5, 6)
|
||||
updeepCurryAdd4(u._, 4, u._, 6)(3, 4)
|
||||
updeepCurryAdd2(3)(4)
|
||||
updeepCurryAdd2(3, 4)
|
||||
},
|
||||
'lodash curry': () => {
|
||||
lodashCurryAdd4(3)(4)(5)(6)
|
||||
lodashCurryAdd4(3, 4, 5, 6)
|
||||
lodashCurryAdd4(_, 4, _, 6)(3, 4)
|
||||
lodashCurryAdd2(3)(4)
|
||||
lodashCurryAdd2(3, 4)
|
||||
},
|
||||
})
|
||||
|
||||
const mapVsLodash = createSuite('Map', {
|
||||
'_.map': () => _.map(array, fakeCurryAdd(8)),
|
||||
'u.map': () => u.map(fakeCurryAdd(8), array),
|
||||
})
|
||||
|
||||
const fn = (a, b, c, d, e) => a + b + c + d + e
|
||||
const fnControl = (a, b, c, d, e) => fn(a, b, c, d, e)
|
||||
const fnApply = (...args) => fn(...args)
|
||||
const fnDestructure = (...args) => {
|
||||
const [a, b, c, d, e] = args
|
||||
return fn(a, b, c, d, e)
|
||||
}
|
||||
const applyVsDestructure = createSuite('apply vs destructure', {
|
||||
control: () => fnControl(1, 2, 3, 4, 5),
|
||||
apply: () => fnApply(1, 2, 3, 4, 5),
|
||||
destructure: () => fnDestructure(1, 2, 3, 4, 5),
|
||||
})
|
||||
|
||||
curryVsLodash()
|
||||
mapVsLodash()
|
||||
// applyVsDestructure();
|
Loading…
Reference in New Issue
Block a user