forked from noir-lang/noir-gates-diff
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from noir-lang/mv/compilation-report
feat: Compilation report
- Loading branch information
Showing
10 changed files
with
269 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import { CompilationReport } from "./types"; | ||
|
||
export const compilationReports = (content: string): CompilationReport[] => { | ||
return JSON.parse(content).compilation_reports; | ||
}; | ||
|
||
export const formatCompilationReport = (compilationReports: CompilationReport[]): string => { | ||
let markdown = "## Compilation Sample\n | Program | Compilation Time |\n | --- | --- |\n"; | ||
for (let i = 0; i < compilationReports.length; i++) { | ||
markdown = markdown.concat( | ||
" | ", | ||
compilationReports[i].artifact_name, | ||
" | ", | ||
compilationReports[i].time, | ||
" |\n" | ||
); | ||
} | ||
return markdown; | ||
}; | ||
|
||
export const computeCompilationDiff = ( | ||
refReports: CompilationReport[], | ||
compilationReports: CompilationReport[] | ||
): string => { | ||
let markdown = ""; | ||
const diff_percentage = []; | ||
let diff_column = false; | ||
if (refReports.length === compilationReports.length) { | ||
for (let i = 0; i < refReports.length; i++) { | ||
let diff_str = "N/A"; | ||
if (refReports[i].artifact_name === compilationReports[i].artifact_name) { | ||
const compTimeString = compilationReports[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 = "## Compilation Sample\n | Program | Compilation Time | % |\n | --- | --- | --- |\n"; | ||
for (let i = 0; i < diff_percentage.length; i++) { | ||
markdown = markdown.concat( | ||
" | ", | ||
compilationReports[i].artifact_name, | ||
" | ", | ||
compilationReports[i].time, | ||
" | ", | ||
diff_percentage[i], | ||
" |\n" | ||
); | ||
} | ||
} else { | ||
markdown = formatCompilationReport(compilationReports); | ||
} | ||
|
||
return markdown; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import * as fs from "fs"; | ||
|
||
import { computeCompilationDiff, formatCompilationReport } from "../src/compilation_report"; | ||
import { compilationReports } from "../src/report"; | ||
|
||
const srcContent = fs.readFileSync("tests/mocks/1-1-compilation-report.json", "utf8"); | ||
const ref_1_Content = fs.readFileSync("tests/mocks/1-1-compilation-report.json", "utf8"); | ||
const ref_2_Content = fs.readFileSync("tests/mocks/1-2-compilation-report.json", "utf8"); | ||
|
||
const compReports = compilationReports(srcContent); | ||
|
||
describe("Markdown format", () => { | ||
it("should generate markdown format", () => { | ||
expect(compReports.length).toBeGreaterThan(0); | ||
const markdown = formatCompilationReport(compReports); | ||
expect(markdown.length).toBeGreaterThan(0); | ||
}); | ||
|
||
it("should generate diff report format", () => { | ||
const ref_1_Reports = compilationReports(ref_1_Content); | ||
const ref_2_Reports = compilationReports(ref_2_Content); | ||
expect(ref_1_Reports.length).toBeGreaterThan(0); | ||
expect(ref_1_Reports.length).toBe(ref_2_Reports.length); | ||
const markdown = computeCompilationDiff(ref_1_Reports, ref_2_Reports); | ||
fs.writeFileSync("tests/mocks/1-2-compilation.md", markdown); | ||
expect(markdown.length).toBeGreaterThan(0); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{"compilation_reports": [ | ||
{ | ||
"artifact_name":"keccak256", | ||
"time":"0m0.280s" | ||
|
||
}, | ||
{ | ||
"artifact_name":"workspace", | ||
"time":"0m0.271s" | ||
|
||
}, | ||
{ | ||
"artifact_name":"regression_4709", | ||
"time":"0m1.796s" | ||
|
||
}, | ||
{ | ||
"artifact_name":"ram_blowup_regression", | ||
"time":"0m20.566s" | ||
|
||
} | ||
]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{"compilation_reports": [ | ||
{ | ||
"artifact_name":"keccak256", | ||
"time":"0m0.325s" | ||
|
||
}, | ||
{ | ||
"artifact_name":"workspace", | ||
"time":"0m0.300s" | ||
|
||
}, | ||
{ | ||
"artifact_name":"regression_4709", | ||
"time":"0m1.842s" | ||
|
||
}, | ||
{ | ||
"artifact_name":"ram_blowup_regression", | ||
"time":"0m20.526s" | ||
|
||
} | ||
]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
## Compilation Sample | ||
| Program | Compilation Time | % | | ||
| --- | --- | --- | | ||
| keccak256 | 0m0.325s | 16% | | ||
| workspace | 0m0.300s | 10% | | ||
| regression_4709 | 0m1.842s | 2% | | ||
| ram_blowup_regression | 0m20.526s | -1% | |