Skip to content

Commit

Permalink
Improve benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed May 28, 2019
1 parent 24a8d40 commit 5c7243f
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 104 deletions.
69 changes: 0 additions & 69 deletions benchmarks/format.js

This file was deleted.

29 changes: 12 additions & 17 deletions benchmarks/main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import testCartesian from '../src/main.js'
import fastCartesian from '../src/main.js'

import { printResults } from './print.js'
import { getArray } from './array.js'
Expand All @@ -10,30 +10,25 @@ import { getArray } from './array.js'
/// [[0, 1, 2, 3]] (1 dimension)
// [[0, 1], [0, 1]] (2 dimensions)
// [[0], [0], [0], [0]] (4 dimensions)
const getArgs = function(size) {
return getArray(size).map((value, index) => getArg(index, size))
const getVariants = function(size) {
const variantsA = getArray(size).map((value, index) =>
getVariant(index, size),
)
return Object.fromEntries(variantsA)
}

const getArg = function(index, size) {
const getVariant = function(index, size) {
const dimensions = 2 ** index
const unitLength = 2 ** (2 ** (size - index - 1))
const title = `${dimensions} dimensions`
const unit = getArray(unitLength)
const argsA = getArray(dimensions).map(() => unit)
return [{ title, args: argsA }]
const args = getArray(dimensions).map(() => unit)
return [title, args]
}

const allArgs = getArgs(5)
const variants = getVariants(5)

printResults(
[
{
name: 'test-cartesian',
func: ({ args }) => testCartesian(...args),
args: allArgs,
},
],
{
count: 1e2,
},
[{ name: 'test-cartesian', func: fastCartesian, variants }],
{ count: 1e2 },
)
20 changes: 12 additions & 8 deletions benchmarks/results.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
import { getArray } from './array.js'
import { getTitles } from './format.js'
import { measure } from './measure.js'
import { average } from './average.js'

export const getResults = function(funcs, { count }) {
const countA = getArray(count)
return funcs.flatMap(({ name, func, args: allArgs = [[]] }) =>
getResult({ name, func, allArgs, count: countA }),
return funcs.flatMap(({ name, func, variants }) =>
getResult({ name, func, variants, count: countA }),
)
}

const getResult = function({ name, func, allArgs, count }) {
return allArgs.map(args => getArgResult({ name, func, args, count }))
const getResult = function({ name, func, variants, count }) {
if (variants === undefined) {
return getArgResult({ name, func, count })
}

return Object.entries(variants).map(([variantTitle, args]) =>
getArgResult({ name, func, args, variantTitle, count }),
)
}

const getArgResult = function({ name, func, args, count }) {
const argsTitle = getTitles(args)
const title = `${name} with ${argsTitle}`
const getArgResult = function({ name, func, args = [], variantTitle, count }) {
const title = variantTitle === undefined ? name : `${name} (${variantTitle})`

const funcA = func.bind(null, ...args)
const durations = count.map(() => measure(funcA))
Expand Down
8 changes: 0 additions & 8 deletions benchmarks/utils.js

This file was deleted.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@
"ava": "^1.4.1",
"gulp": "^4.0.2",
"gulp-shared-tasks": "^0.28.2",
"husky": "^2.3.0",
"pretty-format": "^24.8.0"
"husky": "^2.3.0"
},
"engines": {
"node": ">=8.12.0"
Expand Down

0 comments on commit 5c7243f

Please sign in to comment.