Skip to content

Instantly share code, notes, and snippets.

@thlorenz
Last active August 13, 2018 20:37
Show Gist options
  • Save thlorenz/245dc6a701b226925a89ad699a78f896 to your computer and use it in GitHub Desktop.
Save thlorenz/245dc6a701b226925a89ad699a78f896 to your computer and use it in GitHub Desktop.
Provide benchmark.js interface to just run functions meant to be benchmarked, i.e. to collect deoptimization info
'use strict'
const deferred = {
resolve: function dontCare() {}
}
class DeoptMark {
constructor({ ITER = 1E3 } = {}) {
this._ITER = ITER
this._fns = []
}
add(name, fn, opts = {}) {
this._fns.push({ name, fn, opts })
}
run() {
for (const { name, fn, opts } of this._fns) {
console.log(`Running ${name}`)
const ctx = {}
if (typeof opts.onStart === 'function') {
opts.onStart.call(ctx)
}
for (var i = 0; i < this._ITER; i++) {
fn.call(ctx, deferred)
}
}
}
}
const init = require(process.argv[2])
const suite = new DeoptMark()
suite.cacheSizes = [16 ** 2, 16 ** 3, 16 ** 4]
init(suite)
suite.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment