mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-30 02:19:52 +02:00
Remove ludicrous amount of setup work that was needed to prevent memoization
This commit is contained in:
@@ -22,6 +22,8 @@ const readMetadata = require('read-metadata')
|
|||||||
const { Raw } = require('..')
|
const { Raw } = require('..')
|
||||||
const { resolve } = require('path')
|
const { resolve } = require('path')
|
||||||
|
|
||||||
|
window.__NO_MEMOIZE = true
|
||||||
|
|
||||||
const DEFAULT_BENCHMARK = {
|
const DEFAULT_BENCHMARK = {
|
||||||
setup(state) { return state },
|
setup(state) { return state },
|
||||||
run(state) {}
|
run(state) {}
|
||||||
@@ -95,27 +97,19 @@ function runBenchmarks() {
|
|||||||
// memoization between calls to `fn`
|
// memoization between calls to `fn`
|
||||||
const scope = global.getScope()
|
const scope = global.getScope()
|
||||||
|
|
||||||
let states = []
|
const state =
|
||||||
let numberOfExecution = this.count
|
// Each benchmark is given the chance to do its own setup
|
||||||
while (numberOfExecution--) {
|
scope.benchmark.setup(
|
||||||
states.push(
|
scope.Raw.deserialize(scope.input, { terse: true })
|
||||||
// Each benchmark is given the chance to do its own setup
|
)
|
||||||
scope.benchmark.setup(
|
|
||||||
scope.Raw.deserialize(scope.input, { terse: true })
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
let stateIndex = 0
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// Because of the way BenchmarkJS compiles the functions,
|
// Because of the way BenchmarkJS compiles the functions,
|
||||||
// the variables declared in `setup` are visible to `fn`
|
// the variables declared in `setup` are visible to `fn`
|
||||||
|
|
||||||
fn() {
|
fn() {
|
||||||
scope.benchmark.run(states[stateIndex]) // eslint-disable-line no-undef
|
scope.benchmark.run(state) // eslint-disable-line no-undef
|
||||||
// Next call will use another State instance
|
// Next call will use another State instance
|
||||||
stateIndex++ // eslint-disable-line no-undef
|
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user