Skip to content

Commit

Permalink
Merge pull request #5 from noir-lang/mv/initial-exec-time-report
Browse files Browse the repository at this point in the history
feat: Initial execution time report
  • Loading branch information
vezenovm authored Dec 19, 2024
2 parents 5fb7f20 + 0954121 commit c05e03e
Show file tree
Hide file tree
Showing 6 changed files with 181 additions and 1 deletion.
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ inputs:
description: States whether we want to generate a report of memory usage.
default: false
required: false
execution_report:
description: States whether we want to generate a report of execution times.
default: false
required: false

outputs:
shell:
Expand Down
76 changes: 76 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,72 @@ const computeCompilationDiff = (refReports, compilationReports) => {
exports.computeCompilationDiff = computeCompilationDiff;


/***/ }),

/***/ 1233:
/***/ ((__unused_webpack_module, exports) => {

"use strict";

Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.computeExecutionDiff = exports.formatExecutionReport = exports.executionReports = void 0;
const executionReports = (content) => {
return JSON.parse(content).execution_reports;
};
exports.executionReports = executionReports;
const formatExecutionReport = (executionReports) => {
let markdown = "## Execution Sample\n | Program | Execution Time |\n | --- | --- |\n";
for (let i = 0; i < executionReports.length; i++) {
markdown = markdown.concat(" | ", executionReports[i].artifact_name, " | ", executionReports[i].time, " |\n");
}
return markdown;
};
exports.formatExecutionReport = formatExecutionReport;
const computeExecutionDiff = (refReports, executionReports) => {
let markdown = "";
const diff_percentage = [];
let diff_column = false;
if (refReports.length === executionReports.length) {
for (let i = 0; i < refReports.length; i++) {
let diff_str = "N/A";
if (refReports[i].artifact_name === executionReports[i].artifact_name) {
const compTimeString = executionReports[i].time;
const refTimeString = refReports[i].time;
const compTimeSegments = compTimeString.split("m");
const refTimeSegments = refTimeString.split("m");
const minutesString = compTimeSegments[0];
const refMinutesString = refTimeSegments[0];
const compMinutesValue = parseInt(minutesString);
const refMinutesValue = parseInt(refMinutesString);
const secondsString = compTimeSegments[1];
const compSecondsValue = parseFloat(secondsString.substring(0, secondsString.length - 1));
const compSeconds = compMinutesValue * 60 + compSecondsValue;
const refSecondsString = refTimeSegments[1];
const refSecondsValue = parseFloat(refSecondsString.substring(0, refSecondsString.length - 1));
const refSeconds = refMinutesValue * 60 + refSecondsValue;
const diff = Math.floor(((compSeconds - refSeconds) / refSeconds) * 100);
if (diff != 0) {
diff_column = true;
}
diff_str = diff.toString() + "%";
}
diff_percentage.push(diff_str);
}
}
if (diff_column == true) {
markdown = "## Execution Sample\n | Program | Execution Time | % |\n | --- | --- | --- |\n";
for (let i = 0; i < diff_percentage.length; i++) {
markdown = markdown.concat(" | ", executionReports[i].artifact_name, " | ", executionReports[i].time, " | ", diff_percentage[i], " |\n");
}
}
else {
markdown = (0, exports.formatExecutionReport)(executionReports);
}
return markdown;
};
exports.computeExecutionDiff = computeExecutionDiff;


/***/ }),

/***/ 4822:
Expand Down Expand Up @@ -122,10 +188,12 @@ const artifact = __importStar(__nccwpck_require__(2605));
const core = __importStar(__nccwpck_require__(2186));
const github_1 = __nccwpck_require__(5438);
const compilation_report_1 = __nccwpck_require__(6423);
const execution_report_1 = __nccwpck_require__(1233);
const report_1 = __nccwpck_require__(8269);
const token = process.env.GITHUB_TOKEN || core.getInput("token");
const report = core.getInput("report");
const memory_report = core.getInput("memory_report");
const execution_report = core.getInput("execution_report");
const baseBranch = core.getInput("base");
const headBranch = core.getInput("head");
const baseBranchEscaped = baseBranch.replace(/[/\\]/g, "-");
Expand Down Expand Up @@ -222,13 +290,21 @@ function run() {
referenceContent !== null && referenceContent !== void 0 ? referenceContent : (referenceContent = compareContent); // if no source reports were loaded, defaults to the current reports
core.info("About to check memory reports");
const isMemoryReport = memory_report === "true";
const isExecutionReport = execution_report === "true";
if (isMemoryReport) {
core.info(`Format Memory markdown rows`);
const memoryContent = (0, report_1.memoryReports)(compareContent);
const referenceReports = (0, report_1.memoryReports)(referenceContent);
const markdown = (0, report_1.computeMemoryDiff)(referenceReports, memoryContent);
core.setOutput("markdown", markdown);
}
else if (isExecutionReport) {
core.info(`Format Execution report markdown rows`);
const compilationContent = (0, execution_report_1.executionReports)(compareContent);
const referenceReports = (0, execution_report_1.executionReports)(referenceContent);
const markdown = (0, execution_report_1.computeExecutionDiff)(referenceReports, compilationContent);
core.setOutput("markdown", markdown);
}
else {
core.info(`Format Compilation report markdown rows`);
const compilationContent = (0, report_1.compilationReports)(compareContent);
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

82 changes: 82 additions & 0 deletions src/execution_report.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { ExecutionReport } from "./types";

export const executionReports = (content: string): ExecutionReport[] => {
return JSON.parse(content).execution_reports;
};

export const formatExecutionReport = (executionReports: ExecutionReport[]): string => {
let markdown = "## Execution Sample\n | Program | Execution Time |\n | --- | --- |\n";
for (let i = 0; i < executionReports.length; i++) {
markdown = markdown.concat(
" | ",
executionReports[i].artifact_name,
" | ",
executionReports[i].time,
" |\n"
);
}
return markdown;
};

export const computeExecutionDiff = (
refReports: ExecutionReport[],
executionReports: ExecutionReport[]
): string => {
let markdown = "";
const diff_percentage = [];
let diff_column = false;
if (refReports.length === executionReports.length) {
for (let i = 0; i < refReports.length; i++) {
let diff_str = "N/A";
if (refReports[i].artifact_name === executionReports[i].artifact_name) {
const compTimeString = executionReports[i].time;
const refTimeString = refReports[i].time;
const compTimeSegments = compTimeString.split("m");
const refTimeSegments = refTimeString.split("m");

const minutesString = compTimeSegments[0];
const refMinutesString = refTimeSegments[0];

const compMinutesValue = parseInt(minutesString);
const refMinutesValue = parseInt(refMinutesString);

const secondsString = compTimeSegments[1];
const compSecondsValue = parseFloat(secondsString.substring(0, secondsString.length - 1));
const compSeconds = compMinutesValue * 60 + compSecondsValue;

const refSecondsString = refTimeSegments[1];
const refSecondsValue = parseFloat(
refSecondsString.substring(0, refSecondsString.length - 1)
);
const refSeconds = refMinutesValue * 60 + refSecondsValue;

const diff = Math.floor(((compSeconds - refSeconds) / refSeconds) * 100);
if (diff != 0) {
diff_column = true;
}
diff_str = diff.toString() + "%";
}

diff_percentage.push(diff_str);
}
}

if (diff_column == true) {
markdown = "## Execution Sample\n | Program | Execution Time | % |\n | --- | --- | --- |\n";
for (let i = 0; i < diff_percentage.length; i++) {
markdown = markdown.concat(
" | ",
executionReports[i].artifact_name,
" | ",
executionReports[i].time,
" | ",
diff_percentage[i],
" |\n"
);
}
} else {
markdown = formatExecutionReport(executionReports);
}

return markdown;
};
9 changes: 9 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import * as core from "@actions/core";
import { context, getOctokit } from "@actions/github";

import { computeCompilationDiff } from "./compilation_report";
import { computeExecutionDiff, executionReports } from "./execution_report";
import { memoryReports, computeMemoryDiff, compilationReports } from "./report";

const token = process.env.GITHUB_TOKEN || core.getInput("token");
const report = core.getInput("report");
const memory_report = core.getInput("memory_report");
const execution_report = core.getInput("execution_report");

const baseBranch = core.getInput("base");
const headBranch = core.getInput("head");
Expand Down Expand Up @@ -105,12 +107,19 @@ async function run() {
core.info("About to check memory reports");

const isMemoryReport = memory_report === "true";
const isExecutionReport = execution_report === "true";
if (isMemoryReport) {
core.info(`Format Memory markdown rows`);
const memoryContent = memoryReports(compareContent);
const referenceReports = memoryReports(referenceContent);
const markdown = computeMemoryDiff(referenceReports, memoryContent);
core.setOutput("markdown", markdown);
} else if (isExecutionReport) {
core.info(`Format Execution report markdown rows`);
const compilationContent = executionReports(compareContent);
const referenceReports = executionReports(referenceContent);
const markdown = computeExecutionDiff(referenceReports, compilationContent);
core.setOutput("markdown", markdown);
} else {
core.info(`Format Compilation report markdown rows`);
const compilationContent = compilationReports(compareContent);
Expand Down
9 changes: 9 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,12 @@ export interface CompilationReport {
export interface CompilationReports {
compilation_reports: CompilationReport[];
}

export interface ExecutionReport {
artifact_name: string;
time: string;
}

export interface ExecutionReports {
compilation_reports: ExecutionReport[];
}

0 comments on commit c05e03e

Please sign in to comment.