@best/runtime
Advanced tools
Comparing version 4.0.0-alpha6 to 4.0.0-alpha7
@@ -16,6 +16,6 @@ const BEFORE_ALL = 'beforeAll'; | ||
export const PRIMITIVE_NODE_TYPES = { | ||
GROUP: "group", | ||
BENCHMARK: "benchmark", | ||
RUN: "run" | ||
GROUP: 'group', | ||
BENCHMARK: 'benchmark', | ||
RUN: 'run', | ||
}; | ||
//# sourceMappingURL=constants.js.map | ||
//# sourceMappingURL=constants.js.map |
import { initializeBenchmarkConfig, getBenckmarkState } from './state'; | ||
import { runBenchmark as _runBenchmark } from './runner'; | ||
export * from './primitives'; | ||
const setupBenchmark = (config) => initializeBenchmarkConfig(config); | ||
const runBenchmark = async (config) => { | ||
const setupBenchmark = config => initializeBenchmarkConfig(config); | ||
const runBenchmark = async config => { | ||
if (config) { | ||
@@ -24,2 +24,2 @@ setupBenchmark(config); | ||
}); | ||
//# sourceMappingURL=index.js.map | ||
//# sourceMappingURL=index.js.map |
@@ -26,4 +26,6 @@ import { makeDescribe, makeBenchmark, makeBenchmarkRun } from './utils/primitives-nodes'; | ||
} | ||
if (currentDescribeBlock.type === "benchmark" && !currentDescribeBlock.run) { | ||
throw new Error(`Benchmark "${currentDescribeBlock.name}" must have a 'run()' function or contain benchmarks inside.`); | ||
if (currentDescribeBlock.type === 'benchmark' && !currentDescribeBlock.run) { | ||
throw new Error( | ||
`Benchmark "${currentDescribeBlock.name}" must have a 'run()' function or contain benchmarks inside.`, | ||
); | ||
} | ||
@@ -57,2 +59,2 @@ if (currentDescribeBlock.parent) { | ||
export default handler; | ||
//# sourceMappingURL=primitives-handler.js.map | ||
//# sourceMappingURL=primitives-handler.js.map |
@@ -20,8 +20,8 @@ import { dispatch } from './state'; | ||
const _addHook = (fn, hookType) => dispatch({ nodeName: 'hook', fn, hookType, nodeType: 'add_hook' }); | ||
const beforeAll = (fn) => _addHook(fn, HOOKS.BEFORE_ALL); | ||
const before = (fn) => _addHook(fn, HOOKS.BEFORE); | ||
const afterAll = (fn) => _addHook(fn, HOOKS.AFTER_ALL); | ||
const after = (fn) => _addHook(fn, HOOKS.AFTER); | ||
const run = (fn) => dispatch({ nodeName: 'run', fn, nodeType: RUN_BENCHMARK }); | ||
const beforeAll = fn => _addHook(fn, HOOKS.BEFORE_ALL); | ||
const before = fn => _addHook(fn, HOOKS.BEFORE); | ||
const afterAll = fn => _addHook(fn, HOOKS.AFTER_ALL); | ||
const after = fn => _addHook(fn, HOOKS.AFTER); | ||
const run = fn => dispatch({ nodeName: 'run', fn, nodeType: RUN_BENCHMARK }); | ||
export { describe, benchmark, beforeAll, before, afterAll, after, run }; | ||
//# sourceMappingURL=primitives.js.map | ||
//# sourceMappingURL=primitives.js.map |
@@ -10,2 +10,2 @@ export function normalizeResults(benchmarkState) { | ||
} | ||
//# sourceMappingURL=results.js.map | ||
//# sourceMappingURL=results.js.map |
import { raf, time, nextTick, withMacroTask, formatTime } from './utils/timers'; | ||
import { HOOKS } from './constants'; | ||
export var BenchmarkMeasureType; | ||
(function (BenchmarkMeasureType) { | ||
BenchmarkMeasureType["Execute"] = "BEST/execute"; | ||
BenchmarkMeasureType["Before"] = "BEST/before"; | ||
BenchmarkMeasureType["After"] = "BEST/after"; | ||
(function(BenchmarkMeasureType) { | ||
BenchmarkMeasureType['Execute'] = 'BEST/execute'; | ||
BenchmarkMeasureType['Before'] = 'BEST/before'; | ||
BenchmarkMeasureType['After'] = 'BEST/after'; | ||
})(BenchmarkMeasureType || (BenchmarkMeasureType = {})); | ||
const _initHandlers = () => Object.values(HOOKS).reduce((o, k) => { | ||
o[k] = []; | ||
return o; | ||
}, {}); | ||
const _initHooks = (hooks) => hooks.reduce((m, { type, fn }) => { | ||
m[type].push(fn); | ||
return m; | ||
}, _initHandlers()); | ||
const _initHandlers = () => | ||
Object.values(HOOKS).reduce((o, k) => { | ||
o[k] = []; | ||
return o; | ||
}, {}); | ||
const _initHooks = hooks => | ||
hooks.reduce((m, { type, fn }) => { | ||
m[type].push(fn); | ||
return m; | ||
}, _initHandlers()); | ||
const _forceGC = () => window.gc && window.gc(); | ||
@@ -44,4 +46,3 @@ function startMeasure(markName, type) { | ||
})(); | ||
} | ||
else { | ||
} else { | ||
benchmarkNode.aggregate = formatTime(time() - benchmarkNode.startedAt); | ||
@@ -51,4 +52,3 @@ endMeasure(markName, BenchmarkMeasureType.Execute); | ||
} | ||
} | ||
catch (e) { | ||
} catch (e) { | ||
benchmarkNode.aggregate = -1; | ||
@@ -110,2 +110,2 @@ endMeasure(markName, BenchmarkMeasureType.Execute); | ||
}; | ||
//# sourceMappingURL=run_iteration.js.map | ||
//# sourceMappingURL=run_iteration.js.map |
import { getBenchmarkRootNode } from './state'; | ||
import { runBenchmarkIteration } from './run_iteration'; | ||
import { normalizeResults } from './results'; | ||
import { validateState } from "./utils/validate"; | ||
import { validateState } from './utils/validate'; | ||
function collectNodeResults(node) { | ||
@@ -12,6 +12,5 @@ const { name, aggregate, startedAt, run, children } = node; | ||
resultNode.metrics = run.metrics; | ||
} else if (children) { | ||
resultNode.nodes = children.map(c => collectNodeResults(c)); | ||
} | ||
else if (children) { | ||
resultNode.nodes = children.map((c) => collectNodeResults(c)); | ||
} | ||
return resultNode; | ||
@@ -43,2 +42,2 @@ } | ||
} | ||
//# sourceMappingURL=runner.js.map | ||
//# sourceMappingURL=runner.js.map |
import primitivesHandler from './primitives-handler'; | ||
import { makeDescribe } from './utils/primitives-nodes'; | ||
import DEFAULT_STATE from './utils/default-state'; | ||
import cloneState from "./utils/clone-state"; | ||
import cloneState from './utils/clone-state'; | ||
const eventHandlers = [primitivesHandler]; | ||
@@ -14,3 +14,3 @@ const ROOT_DESCRIBE_BLOCK_NAME = typeof BEST_CONFIG !== 'undefined' ? BEST_CONFIG.benchmarkName : 'ROOT_DESCRIBE_BLOCK'; | ||
export const getBenchmarkRootNode = () => getBenckmarkState().rootDescribeBlock; | ||
export const initializeBenchmarkConfig = (newOpts) => { | ||
export const initializeBenchmarkConfig = newOpts => { | ||
if (newOpts.iterations !== undefined) { | ||
@@ -31,7 +31,6 @@ if (newOpts.iterateOnClient === undefined) { | ||
} | ||
} | ||
catch (err) { | ||
} catch (err) { | ||
STATE.benchmarkDefinitionError = err; | ||
} | ||
} | ||
//# sourceMappingURL=state.js.map | ||
//# sourceMappingURL=state.js.map |
export default function cloneState(obj) { | ||
const stateClone = Object.assign({}, obj); | ||
if (stateClone.children) { | ||
stateClone.children = stateClone.children.map((obj) => cloneState(obj)); | ||
stateClone.children = stateClone.children.map(obj => cloneState(obj)); | ||
} | ||
@@ -11,2 +11,2 @@ if (stateClone.run) { | ||
} | ||
//# sourceMappingURL=clone-state.js.map | ||
//# sourceMappingURL=clone-state.js.map |
export default Object.freeze({ | ||
benchmarkName: "", | ||
benchmarkName: '', | ||
useMacroTaskAfterBenchmark: true, | ||
@@ -11,2 +11,2 @@ maxDuration: 1000 * 20, | ||
}); | ||
//# sourceMappingURL=default-state.js.map | ||
//# sourceMappingURL=default-state.js.map |
import { RUN_BENCHMARK } from '../constants'; | ||
export const makeDescribe = (name, parent, mode) => ({ | ||
type: "group", | ||
type: 'group', | ||
mode: parent && !mode ? parent.mode : mode, | ||
@@ -13,3 +13,3 @@ children: [], | ||
export const makeBenchmark = (name, parent, mode) => ({ | ||
type: "benchmark", | ||
type: 'benchmark', | ||
mode: parent && !mode ? parent.mode : mode, | ||
@@ -23,3 +23,3 @@ hooks: [], | ||
export const makeBenchmarkRun = (fn, parent) => ({ | ||
type: "run", | ||
type: 'run', | ||
fn, | ||
@@ -31,4 +31,4 @@ name: RUN_BENCHMARK, | ||
hooks: [], | ||
aggregate: 0 | ||
aggregate: 0, | ||
}); | ||
//# sourceMappingURL=primitives-nodes.js.map | ||
//# sourceMappingURL=primitives-nodes.js.map |
@@ -34,7 +34,8 @@ /* | ||
}; | ||
} | ||
else if (typeof MessageChannel !== 'undefined' && | ||
} else if ( | ||
typeof MessageChannel !== 'undefined' && | ||
(isNative(MessageChannel) || | ||
// PhantomJS | ||
MessageChannel.toString() === '[object MessageChannelConstructor]')) { | ||
MessageChannel.toString() === '[object MessageChannelConstructor]') | ||
) { | ||
const channel = new MessageChannel(); | ||
@@ -46,4 +47,3 @@ const port = channel.port2; | ||
}; | ||
} | ||
else { | ||
} else { | ||
/* istanbul ignore next */ | ||
@@ -61,4 +61,3 @@ macroTimerFunc = () => { | ||
}; | ||
} | ||
else { | ||
} else { | ||
// fallback to macro | ||
@@ -72,4 +71,5 @@ microTimerFunc = macroTimerFunc; | ||
export function withMacroTask(fn) { | ||
return (fn._withTask || | ||
(fn._withTask = function () { | ||
return ( | ||
fn._withTask || | ||
(fn._withTask = function() { | ||
useMacroTask = true; | ||
@@ -79,3 +79,4 @@ const res = fn.apply(null, arguments); | ||
return res; | ||
})); | ||
}) | ||
); | ||
} | ||
@@ -88,8 +89,6 @@ export function nextTick(cb, ctx) { | ||
cb.call(ctx); | ||
} | ||
catch (e) { | ||
} catch (e) { | ||
handleError(e, ctx, 'nextTick'); | ||
} | ||
} | ||
else if (_resolve) { | ||
} else if (_resolve) { | ||
_resolve(ctx); | ||
@@ -102,14 +101,15 @@ } | ||
macroTimerFunc(); | ||
} | ||
else { | ||
} else { | ||
microTimerFunc(); | ||
} | ||
} | ||
return cb ? null : new Promise(resolve => { | ||
_resolve = resolve; | ||
}); | ||
return cb | ||
? null | ||
: new Promise(resolve => { | ||
_resolve = resolve; | ||
}); | ||
} | ||
export const time = window.performance.now.bind(window.performance); | ||
export const formatTime = (t) => Math.round(t * 1000) / 1000; | ||
export const formatTime = t => Math.round(t * 1000) / 1000; | ||
export const raf = window && window.requestAnimationFrame ? window.requestAnimationFrame : nextTick; | ||
//# sourceMappingURL=timers.js.map | ||
//# sourceMappingURL=timers.js.map |
@@ -13,2 +13,2 @@ export function validateState(benchmarkState) { | ||
} | ||
//# sourceMappingURL=validate.js.map | ||
//# sourceMappingURL=validate.js.map |
@@ -7,3 +7,3 @@ { | ||
}, | ||
"version": "4.0.0-alpha6", | ||
"version": "4.0.0-alpha7", | ||
"description": "Best Runtime", | ||
@@ -20,3 +20,3 @@ "keywords": [ | ||
], | ||
"gitHead": "790688e72822f83bdd0ccf304b522784fe35dd94" | ||
"gitHead": "fe1d14c11ece42f88c40825d8b46386fb0452cd7" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
18088
495