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
}),
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') }),
)
)
suite(
'All equal - million elements',
add('Imperative', () => {
allEqualImperative(inputMillion)
}),
add('Declarative', () => {
allEqualEveryDeclarative(inputMillion)
}),
cycle(),
complete(),
save({ file: 'all-equal-million', folder: path.join(__dirname, 'results') }),
save({
file: 'all-equal-million',
folder: path.join(__dirname, 'results'),
format: 'chart.html',
}),
)
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' }),
)
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' }),
)
),
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 }),
)
suite(
'All equal - million elements',
add('Imperative', () => {
allEqualImperative(inputMillion)
}),
add('Declarative', () => {
allEqualEveryDeclarative(inputMillion)
}),
cycle(),
complete(),
save({ file: 'all-equal-million', folder: path.join(__dirname, 'results') }),
save({
file: 'all-equal-million',
folder: path.join(__dirname, 'results'),
format: 'chart.html',
}),
)
}
}),
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',
}),
)
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') }),
)
}),
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',
}),
)