瀏覽代碼

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

acheron 2 年之前
父節點
當前提交
9e73317d09

+ 9 - 0
bench/COMPUTE_UNITS.md

@@ -9,8 +9,13 @@ The programs and their tests are located in [/tests/bench](https://github.com/co
 > **Note**
 > **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.
 > 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]
 ## [Unreleased]
 
 
+Solana version: 1.16.0
+
 | Instruction                 | Compute Units | +/- |
 | Instruction                 | Compute Units | +/- |
 | --------------------------- | ------------- | --- |
 | --------------------------- | ------------- | --- |
 | accountInfo1                | 1015          | -   |
 | accountInfo1                | 1015          | -   |
@@ -107,6 +112,8 @@ The programs and their tests are located in [/tests/bench](https://github.com/co
 
 
 ## [0.28.0]
 ## [0.28.0]
 
 
+Solana version: 1.16.0
+
 | Instruction                 | Compute Units | +/-            |
 | Instruction                 | Compute Units | +/-            |
 | --------------------------- | ------------- | -------------- |
 | --------------------------- | ------------- | -------------- |
 | accountInfo1                | 1015          | 🔴 **+6.39%**  |
 | 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]
 ## [0.27.0]
 
 
+Solana version: 1.14.16
+
 | Instruction                 | Compute Units | +/- |
 | Instruction                 | Compute Units | +/- |
 | --------------------------- | ------------- | --- |
 | --------------------------- | ------------- | --- |
 | accountInfo1                | 954           | N/A |
 | accountInfo1                | 954           | N/A |

+ 1 - 1
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.
 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.

+ 1 - 1
tests/bench/scripts/bump-version.ts

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

+ 10 - 8
tests/bench/scripts/sync-markdown.ts

@@ -20,10 +20,8 @@ import { BenchData, Markdown } from "./utils";
           return;
           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
         // Create table
         const table = Markdown.createTable(
         const table = Markdown.createTable(
@@ -33,8 +31,8 @@ import { BenchData, Markdown } from "./utils";
         );
         );
 
 
         bench.compareComputeUnits(
         bench.compareComputeUnits(
-          newComputeUnitsResult,
-          oldComputeUnitsResult,
+          newData.result.computeUnits,
+          oldData.result.computeUnits,
           ({ ixName, newComputeUnits, oldComputeUnits }) => {
           ({ ixName, newComputeUnits, oldComputeUnits }) => {
             if (newComputeUnits === null) {
             if (newComputeUnits === null) {
               // Deleted instruction
               // 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,
+        });
       }
       }
     }
     }
   });
   });

+ 18 - 6
tests/bench/scripts/utils.ts

@@ -256,20 +256,32 @@ export class Markdown {
     await fs.writeFile(this.#path, this.#text);
     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;
     const md = this.#text;
 
 
-    let titleStartIndex = md.indexOf(`[${version}]`);
+    const title = `[${params.version}]`;
+    let titleStartIndex = md.indexOf(title);
     if (titleStartIndex === -1) {
     if (titleStartIndex === -1) {
       titleStartIndex = md.indexOf(Markdown.#UNRELEASED_VERSION);
       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 =
     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 */
   /** Bump the version to the given version */

+ 1 - 2
tests/bench/tsconfig.json

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