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'),
}),
)
const { add, complete, cycle, save, suite } = require('benny')
const path = require('path')
module.exports = suite(
'Custom logging - console.log',
add('Add two numbers', () => {
1 + 1
}),
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:
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'),
}),
)
module.exports = suite(
'Custom logging - console.log',
add('Add two numbers', () => {
1 + 1
}),
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'),
}),
)
const { add, complete, cycle, save, suite } = require('benny')
const path = require('path')
const delay = (seconds) =>
new Promise((resolve) => setTimeout(resolve, seconds * 1000))
module.exports = suite(
'Async madness',
add('Async benchmark without setup', async () => {
// You can use await or return - works the same,
// (async function always returns a Promise)
await delay(0.5) // Resulting in 2 ops/s
}),
add('Async benchmark without setup - many async operations', async () => {
await delay(0.5)
await delay(0.5)
// Resulting in 1 ops/s
}),
add('Async benchmark with some setup', async () => {
await delay(2) // Setup can be async, it will not affect the results
return async () => {
await delay(0.5) // Still 2 ops/s
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 { add, complete, cycle, save, suite } = require('benny')
const path = require('path')
const delay = (seconds) =>
new Promise((resolve) => setTimeout(resolve, seconds * 1000))
module.exports = suite(
'Async madness',
add('Async benchmark without setup', async () => {
// You can use await or return - works the same,
// (async function always returns a Promise)
await delay(0.5) // Resulting in 2 ops/s
}),
add('Async benchmark without setup - many async operations', async () => {
await delay(0.5)
await delay(0.5)
// Resulting in 1 ops/s
}),
add('Async benchmark with some setup', async () => {
await delay(2) // Setup can be async, it will not affect the results
const { add, complete, cycle, save, suite } = require('benny')
const path = require('path')
const { pipe } = require('@arrows/composition')
const A = require('@arrows/array')
const R = require('ramda')
const _ = require('lodash/fp')
// Prepare an array of 1..10
const initialArr = Array.from({ length: 100 }, (_, i) => i + 1)
// Helper functions identical for each case
const isOdd = (x) => x % 2 !== 0
const triple = (x) => x * 3
const sum = (a, b) => a + b
module.exports = suite(
'Functional array composition',
add('ramda', () => {
R.pipe(
// @ts-ignore
R.filter(isOdd),
R.map(triple),
R.reduce(sum, 0),
)(initialArr)
}),
add('@arrows', () => {
pipe(
A.filter(isOdd),
A.map(triple),
A.reduce(sum, 0),
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') }),
)
await delay(2) // Setup can be async, it will not affect the 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') }),
)