bench: Show Solana version used in tests (#2543)

This commit is contained in:
acheron 2023-06-24 23:28:16 +02:00 committed by GitHub
parent d41e513351
commit 9e73317d09
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 40 additions and 18 deletions

View File

@ -9,8 +9,13 @@ The programs and their tests are located in [/tests/bench](https://github.com/co
> **Note**
> The results documented in this file are autogenerated. Running the tests will update the current results when necessary, manually editing the results should be avoided.
> **Warning**
> The results may vary depending on Solana version.
## [Unreleased]
Solana version: 1.16.0
| Instruction | Compute Units | +/- |
| --------------------------- | ------------- | --- |
| accountInfo1 | 1015 | - |
@ -107,6 +112,8 @@ The programs and their tests are located in [/tests/bench](https://github.com/co
## [0.28.0]
Solana version: 1.16.0
| Instruction | Compute Units | +/- |
| --------------------------- | ------------- | -------------- |
| accountInfo1 | 1015 | 🔴 **+6.39%** |
@ -203,6 +210,8 @@ The programs and their tests are located in [/tests/bench](https://github.com/co
## [0.27.0]
Solana version: 1.14.16
| Instruction | Compute Units | +/- |
| --------------------------- | ------------- | --- |
| accountInfo1 | 954 | N/A |

View File

@ -28,4 +28,4 @@ The following scripts are useful when making changes to how benchmarking works.
The following script is only for the maintainer(s) of Anchor.
`anchor run bump-version -- <VERSION>`: Bump the version in all benchmark files.
`anchor run bump-version -- --anchor-version <VERSION>`: Bump the version in all benchmark files.

View File

@ -15,7 +15,7 @@ import {
if (newVersion === "unreleased") {
console.error(
`Usage: anchor run bump-version ${ANCHOR_VERSION_ARG} <VERSION>`
`Usage: anchor run bump-version -- ${ANCHOR_VERSION_ARG} <VERSION>`
);
process.exitCode = 1;
return;

View File

@ -20,10 +20,8 @@ import { BenchData, Markdown } from "./utils";
return;
}
const newComputeUnitsResult =
bench.get(nextVersion).result.computeUnits;
const oldComputeUnitsResult =
bench.get(currentVersion).result.computeUnits;
const newData = bench.get(nextVersion);
const oldData = bench.get(currentVersion);
// Create table
const table = Markdown.createTable(
@ -33,8 +31,8 @@ import { BenchData, Markdown } from "./utils";
);
bench.compareComputeUnits(
newComputeUnitsResult,
oldComputeUnitsResult,
newData.result.computeUnits,
oldData.result.computeUnits,
({ ixName, newComputeUnits, oldComputeUnits }) => {
if (newComputeUnits === null) {
// Deleted instruction
@ -69,8 +67,12 @@ import { BenchData, Markdown } from "./utils";
}
);
// Update version's table
markdown.updateTable(nextVersion, table);
// Update version data
markdown.updateVersion({
version: nextVersion,
solanaVersion: newData.solanaVersion,
table,
});
}
}
});

View File

@ -256,20 +256,32 @@ export class Markdown {
await fs.writeFile(this.#path, this.#text);
}
/** Change version table with the given table */
updateTable(version: string, table: MarkdownTable) {
/** Change the version's content with the given `solanaVersion` and `table` */
updateVersion(params: {
version: Version;
solanaVersion: string;
table: MarkdownTable;
}) {
const md = this.#text;
let titleStartIndex = md.indexOf(`[${version}]`);
const title = `[${params.version}]`;
let titleStartIndex = md.indexOf(title);
if (titleStartIndex === -1) {
titleStartIndex = md.indexOf(Markdown.#UNRELEASED_VERSION);
}
const startIndex = titleStartIndex + md.slice(titleStartIndex).indexOf("|");
const endIndex = startIndex + md.slice(startIndex).indexOf("\n\n");
const titleContentStartIndex = titleStartIndex + title.length + 1;
const tableStartIndex =
titleStartIndex + md.slice(titleStartIndex).indexOf("|");
const tableEndIndex =
tableStartIndex + md.slice(tableStartIndex).indexOf("\n\n");
this.#text =
md.slice(0, startIndex) + table.toString() + md.slice(endIndex + 1);
md.slice(0, titleContentStartIndex) +
`Solana version: ${params.solanaVersion}\n\n` +
params.table.toString() +
md.slice(tableEndIndex + 1);
}
/** Bump the version to the given version */

View File

@ -1,7 +1,6 @@
{
"compilerOptions": {
"types": ["mocha", "chai", "node"],
"typeRoots": ["./node_modules/@types"],
"types": ["mocha", "node"],
"lib": ["ES6"],
"module": "commonjs",
"target": "es6",