From 9e73317d0949cfac0f13f70bec6de4359290b04e Mon Sep 17 00:00:00 2001 From: acheron <98934430+acheroncrypto@users.noreply.github.com> Date: Sat, 24 Jun 2023 23:28:16 +0200 Subject: [PATCH] bench: Show Solana version used in tests (#2543) --- bench/COMPUTE_UNITS.md | 9 +++++++++ tests/bench/README.md | 2 +- tests/bench/scripts/bump-version.ts | 2 +- tests/bench/scripts/sync-markdown.ts | 18 ++++++++++-------- tests/bench/scripts/utils.ts | 24 ++++++++++++++++++------ tests/bench/tsconfig.json | 3 +-- 6 files changed, 40 insertions(+), 18 deletions(-) diff --git a/bench/COMPUTE_UNITS.md b/bench/COMPUTE_UNITS.md index 6b724fdbf..547865d41 100644 --- a/bench/COMPUTE_UNITS.md +++ b/bench/COMPUTE_UNITS.md @@ -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 | diff --git a/tests/bench/README.md b/tests/bench/README.md index 061e1d54a..78fb88691 100644 --- a/tests/bench/README.md +++ b/tests/bench/README.md @@ -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 -- `: Bump the version in all benchmark files. +`anchor run bump-version -- --anchor-version `: Bump the version in all benchmark files. diff --git a/tests/bench/scripts/bump-version.ts b/tests/bench/scripts/bump-version.ts index 2d0b32a7e..e4b222b62 100644 --- a/tests/bench/scripts/bump-version.ts +++ b/tests/bench/scripts/bump-version.ts @@ -15,7 +15,7 @@ import { if (newVersion === "unreleased") { console.error( - `Usage: anchor run bump-version ${ANCHOR_VERSION_ARG} ` + `Usage: anchor run bump-version -- ${ANCHOR_VERSION_ARG} ` ); process.exitCode = 1; return; diff --git a/tests/bench/scripts/sync-markdown.ts b/tests/bench/scripts/sync-markdown.ts index 9d510a564..781d99839 100644 --- a/tests/bench/scripts/sync-markdown.ts +++ b/tests/bench/scripts/sync-markdown.ts @@ -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, + }); } } }); diff --git a/tests/bench/scripts/utils.ts b/tests/bench/scripts/utils.ts index 66bfe9bc8..3b9b80233 100644 --- a/tests/bench/scripts/utils.ts +++ b/tests/bench/scripts/utils.ts @@ -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 */ diff --git a/tests/bench/tsconfig.json b/tests/bench/tsconfig.json index df8ea8e38..a53432cd4 100644 --- a/tests/bench/tsconfig.json +++ b/tests/bench/tsconfig.json @@ -1,7 +1,6 @@ { "compilerOptions": { - "types": ["mocha", "chai", "node"], - "typeRoots": ["./node_modules/@types"], + "types": ["mocha", "node"], "lib": ["ES6"], "module": "commonjs", "target": "es6",