UNPKG

@dapplion/benchmark

Version:

Ensures that new code does not introduce performance regressions with CI. Tracks:

96 lines (95 loc) 3.39 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getGaCacheHistoryProvider = getGaCacheHistoryProvider; const node_fs_1 = __importDefault(require("node:fs")); const cache = __importStar(require("@actions/cache")); const local_js_1 = require("./local.js"); const provider_js_1 = require("./provider.js"); /** * Persist results in CSV, one benchmark result per file * * ``` * /$dirpath/52b8122daa9b7a3d0ea0ecfc1ff9eda79a201eb8.csv * ``` * * ```csv * id,averageNs,runsDone,totalMs * sum array with raw for loop,1348118,371,501 * sum array with reduce,16896469,128,2163 * ``` */ function getGaCacheHistoryProvider(cacheKey) { const tmpDir = node_fs_1.default.mkdtempSync("ga-cache-download"); return new GaCacheHistoryProvider(tmpDir, cacheKey); } class GaCacheHistoryProvider extends local_js_1.LocalHistoryProvider { tmpDir; cacheKey; type = provider_js_1.HistoryProviderType.GaCache; initializePromise = null; constructor(tmpDir, cacheKey) { super(tmpDir); this.tmpDir = tmpDir; this.cacheKey = cacheKey; } providerInfo() { return `GaCacheHistoryProvider: cacheKey ${this.cacheKey}`; } async readLatestInBranch(branch) { await this.initialize(); return super.readLatestInBranch(branch); } async writeLatestInBranch(branch, benchmark) { await super.writeLatestInBranch(branch, benchmark); await this.persist(); } async readHistory() { await this.initialize(); return super.readHistory(); } async readHistoryCommit(commitSha) { await this.initialize(); return super.readHistoryCommit(commitSha); } async writeToHistory(benchmark) { await super.writeToHistory(benchmark); await this.persist(); } async initialize() { // eslint-disable-next-line no-console console.log("ENV", process.env); if (this.initializePromise === null) { this.initializePromise = cache.restoreCache([this.tmpDir], this.cacheKey); } return this.initializePromise; } async persist() { await cache.saveCache([this.tmpDir], this.cacheKey); } }