Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
add('Add two numbers', () => {
1 + 1 + 1
}),
add('Add two numbers', () => {
1 + 1 + 1
}),
cycle((result, summary) => {
// This will be replaced in-place by each cycle:
return `Progress: ${
summary.results.filter((result) => result.completed).length
} / ${summary.results.length}`
}),
complete((summary) => {
console.log(`Finished ${summary.results.length} benchmarks!`)
}),
save({
file: 'custom-logging-replace',
folder: path.join(__dirname, 'results'),
}),
)
return async () => {
await delay(0.5) // Still 2 ops/s
}
}),
add('Sync benchmark with some async setup', async () => {
await delay(2) // Setup can be async, it will not affect the results
return () => {
1 + 1 // High ops, not affected by slow, async setup
}
}),
cycle(),
complete(),
save({ file: 'async-madness', folder: path.join(__dirname, 'results') }),
)
const inputHundred = [...'a'.repeat(100)]
const inputMillion = [...'a'.repeat(1000000)]
suite(
'All equal - hundred elements',
add('Imperative', () => {
allEqualImperative(inputHundred)
}),
add('Declarative', () => {
allEqualEveryDeclarative(inputHundred)
}),
cycle(),
complete(),
save({ file: 'all-equal-hundred', folder: path.join(__dirname, 'results') }),
save({
file: 'all-equal-hundred',
folder: path.join(__dirname, 'results'),
format: 'chart.html',
}),
)
suite(
'All equal - million elements',
add('Imperative', () => {
allEqualImperative(inputMillion)
}),
add('Declarative', () => {
newData.foo.bar.bat[1] = 7
}
}),
add('Clone - lodash', () => {
const data = initializeTestData()
return () => {
const newData = _.cloneDeep(data)
newData.foo.bar.baz = 'yo'
newData.foo.bar.bat[1] = 7
}
}),
cycle(),
complete(),
save({ file: 'immutable-trans', folder: path.join(__dirname, 'results') }),
save({
file: 'immutable-trans',
folder: path.join(__dirname, 'results'),
format: 'chart.html',
}),
)
},
),
add(
'Execute multimethod with a thousand complex caseVal methods - last matching',
() => {
const methods = createNMethodsWithComplexCaseVal(1000)
const fn = multi(...methods)
return () =>
fn({ foo: 1000, bar: { baz: 1000, bat: [1000, 1000, 1000] } })
},
),
cycle(),
complete(),
save({ file: `${version}-multimethod-execution`, version }),
)
}),
add('@arrows/array', () => {
A.reduce((a, b) => a + b, 0)(input)
}),
add('@arrows/array first', () => {
A.reduce.first((a, b) => a + b)(input)
}),
add('rambda', () => {
RB.reduce((a, b) => a + b, 0)(input)
}),
cycle(),
complete(),
save({ file: 'reduce' }),
save({ file: 'reduce', format: 'chart.html' }),
)
A.filter(isOdd),
A.map(triple),
A.reduce(sum, 0),
)(initialArr)
}),
add('lodash/fp', () => {
_.pipe(
_.filter(isOdd),
_.map(triple),
_.reduce(sum, 0),
)(initialArr)
}),
cycle(),
complete(),
save({ file: 'composition', folder: path.join(__dirname, 'results') }),
)