UNPKG

@c4312/matcha

Version:

A caffeine driven, simple command line for benchmarking

57 lines 2.65 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const suite_1 = require("./suite"); const options_1 = require("./options"); const reporter_1 = require("./middleware/reporter"); function benchmark({ runFunction, prepare, reporter, middleware, }) { var _a, _b; return __awaiter(this, void 0, void 0, function* () { const suite = new suite_1.MatchaSuite(runFunction); const retainSymbol = Symbol(); let scope = { prefix: '', middleware: (_b = (_a = middleware) === null || _a === void 0 ? void 0 : _a.slice(), (_b !== null && _b !== void 0 ? _b : [])), options: options_1.Options.empty }; scope.middleware.push(reporter_1.reporterMiddleware(reporter)); yield prepare({ bench(name, fn, options) { suite.addCase({ fn, name: scope.prefix + name, middleware: scope.middleware, options: scope.options.merge(options), }); }, suite(name, fn, options) { const previous = scope; scope = { prefix: previous.prefix + name + '#', middleware: previous.middleware, options: previous.options.merge(options), }; fn(); scope = previous; }, set(key, value) { scope.options = scope.options.merge({ [key]: value }); }, retain(value) { // Some expression that'll never evaluate to true, but ensure that V8 // (probably) can't optimize the passed value away. if (retainSymbol === value) { throw new Error('unreachable'); } }, }); yield suite.run(); reporter.onComplete(); }); } exports.benchmark = benchmark; //# sourceMappingURL=runner.js.map