Эх сурвалжийг харах

bench: Add benchmarking for program binary size (#2591)

acheron 2 жил өмнө
parent
commit
4cf447a1c4

+ 49 - 0
bench/BINARY_SIZE.md

@@ -0,0 +1,49 @@
+# Binary Size
+
+All notable changes in program binary size will be documented in this file.
+
+The changes are calculated by comparing the current results with the last version's results. Increase in size is shown with 🔴 and decrease is shown with 🟢.
+
+The programs and their tests are located in [/tests/bench](https://github.com/coral-xyz/anchor/tree/master/tests/bench).
+
+> **Note**
+> 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**
+> Results may vary depending on Solana version.
+
+## [Unreleased]
+
+Solana version: 1.16.0
+
+| Program | Binary Size | +/- |
+| ------- | ----------- | --- |
+| bench   | 1,153,736   | -   |
+
+### Notable changes
+
+---
+
+## [0.28.0]
+
+Solana version: 1.16.0
+
+| Program | Binary Size | +/-                    |
+| ------- | ----------- | ---------------------- |
+| bench   | 1,153,736   | 🔴 **+35,000 (3.13%)** |
+
+### Notable changes
+
+- Upgrading Solana to `1.16`. The difference in binary size between `0.27.0` and `0.28.0` is the direct result of upgrading Solana version(both build tools and crates) ([#2512](https://github.com/coral-xyz/anchor/pull/2512)).
+
+---
+
+## [0.27.0]
+
+Solana version: 1.14.16
+
+| Program | Binary Size | +/- |
+| ------- | ----------- | --- |
+| bench   | 1,118,736   | N/A |
+
+---

+ 261 - 261
bench/COMPUTE_UNITS.md

@@ -7,104 +7,104 @@ The changes are calculated by comparing the current results with the last versio
 The programs and their tests are located in [/tests/bench](https://github.com/coral-xyz/anchor/tree/master/tests/bench).
 
 > **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.
+> 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.
+> Results may vary depending on Solana version.
 
 ## [Unreleased]
 
 Solana version: 1.16.0
 
-| Instruction                 | Compute Units | +/- |
-| --------------------------- | ------------- | --- |
-| accountInfo1                | 1015          | -   |
-| accountInfo2                | 1475          | -   |
-| accountInfo4                | 1964          | -   |
-| accountInfo8                | 3841          | -   |
-| accountEmptyInit1           | 5817          | -   |
-| accountEmpty1               | 1149          | -   |
-| accountEmptyInit2           | 10402         | -   |
-| accountEmpty2               | 1754          | -   |
-| accountEmptyInit4           | 19508         | -   |
-| accountEmpty4               | 2540          | -   |
-| accountEmptyInit8           | 37265         | -   |
-| accountEmpty8               | 5016          | -   |
-| accountSizedInit1           | 5924          | -   |
-| accountSized1               | 1214          | -   |
-| accountSizedInit2           | 10680         | -   |
-| accountSized2               | 1873          | -   |
-| accountSizedInit4           | 19970         | -   |
-| accountSized4               | 2762          | -   |
-| accountSizedInit8           | 38122         | -   |
-| accountSized8               | 5353          | -   |
-| accountUnsizedInit1         | 6052          | -   |
-| accountUnsized1             | 1338          | -   |
-| accountUnsizedInit2         | 10929         | -   |
-| accountUnsized2             | 1778          | -   |
-| accountUnsizedInit4         | 20339         | -   |
-| accountUnsized4             | 3136          | -   |
-| accountUnsizedInit8         | 39096         | -   |
-| accountUnsized8             | 5952          | -   |
-| boxedAccountEmptyInit1      | 6034          | -   |
-| boxedAccountEmpty1          | 888           | -   |
-| boxedAccountEmptyInit2      | 10633         | -   |
-| boxedAccountEmpty2          | 1401          | -   |
-| boxedAccountEmptyInit4      | 19311         | -   |
-| boxedAccountEmpty4          | 2424          | -   |
-| boxedAccountEmptyInit8      | 37136         | -   |
-| boxedAccountEmpty8          | 4659          | -   |
-| boxedAccountSizedInit1      | 6130          | -   |
-| boxedAccountSized1          | 917           | -   |
-| boxedAccountSizedInit2      | 10828         | -   |
-| boxedAccountSized2          | 1463          | -   |
-| boxedAccountSizedInit4      | 19703         | -   |
-| boxedAccountSized4          | 2543          | -   |
-| boxedAccountSizedInit8      | 37919         | -   |
-| boxedAccountSized8          | 4898          | -   |
-| boxedAccountUnsizedInit1    | 6240          | -   |
-| boxedAccountUnsized1        | 972           | -   |
-| boxedAccountUnsizedInit2    | 11048         | -   |
-| boxedAccountUnsized2        | 1570          | -   |
-| boxedAccountUnsizedInit4    | 20138         | -   |
-| boxedAccountUnsized4        | 2768          | -   |
-| boxedAccountUnsizedInit8    | 38791         | -   |
-| boxedAccountUnsized8        | 5347          | -   |
-| boxedInterfaceAccountMint1  | 2296          | -   |
-| boxedInterfaceAccountMint2  | 4129          | -   |
-| boxedInterfaceAccountMint4  | 7783          | -   |
-| boxedInterfaceAccountMint8  | 15281         | -   |
-| boxedInterfaceAccountToken1 | 2023          | -   |
-| boxedInterfaceAccountToken2 | 3582          | -   |
-| boxedInterfaceAccountToken4 | 6692          | -   |
-| boxedInterfaceAccountToken8 | 13098         | -   |
-| interfaceAccountMint1       | 2364          | -   |
-| interfaceAccountMint2       | 5030          | -   |
-| interfaceAccountMint4       | 9803          | -   |
-| interfaceAccountMint8       | 18400         | -   |
-| interfaceAccountToken1      | 2091          | -   |
-| interfaceAccountToken2      | 3948          | -   |
-| interfaceAccountToken4      | 7547          | -   |
-| interface1                  | 1059          | -   |
-| interface2                  | 1479          | -   |
-| interface4                  | 1900          | -   |
-| interface8                  | 3646          | -   |
-| program1                    | 1053          | -   |
-| program2                    | 1467          | -   |
-| program4                    | 1878          | -   |
-| program8                    | 3598          | -   |
-| signer1                     | 1018          | -   |
-| signer2                     | 1484          | -   |
-| signer4                     | 1984          | -   |
-| signer8                     | 3880          | -   |
-| systemAccount1              | 1072          | -   |
-| systemAccount2              | 1590          | -   |
-| systemAccount4              | 2195          | -   |
-| systemAccount8              | 4305          | -   |
-| uncheckedAccount1           | 1014          | -   |
-| uncheckedAccount2           | 1475          | -   |
-| uncheckedAccount4           | 1965          | -   |
-| uncheckedAccount8           | 3841          | -   |
+| Instruction                 | Compute Units | +/-               |
+| --------------------------- | ------------- | ----------------- |
+| accountInfo1                | 1,015         | -                 |
+| accountInfo2                | 1,475         | -                 |
+| accountInfo4                | 1,964         | -                 |
+| accountInfo8                | 3,841         | -                 |
+| accountEmptyInit1           | 5,817         | -                 |
+| accountEmpty1               | 1,149         | -                 |
+| accountEmptyInit2           | 10,402        | -                 |
+| accountEmpty2               | 1,754         | -                 |
+| accountEmptyInit4           | 19,508        | -                 |
+| accountEmpty4               | 2,540         | -                 |
+| accountEmptyInit8           | 37,265        | -                 |
+| accountEmpty8               | 5,016         | -                 |
+| accountSizedInit1           | 5,924         | -                 |
+| accountSized1               | 1,214         | -                 |
+| accountSizedInit2           | 10,680        | -                 |
+| accountSized2               | 1,873         | -                 |
+| accountSizedInit4           | 19,970        | -                 |
+| accountSized4               | 2,762         | -                 |
+| accountSizedInit8           | 38,122        | -                 |
+| accountSized8               | 5,353         | -                 |
+| accountUnsizedInit1         | 6,052         | -                 |
+| accountUnsized1             | 1,338         | -                 |
+| accountUnsizedInit2         | 10,929        | -                 |
+| accountUnsized2             | 1,778         | -                 |
+| accountUnsizedInit4         | 20,339        | -                 |
+| accountUnsized4             | 3,136         | -                 |
+| accountUnsizedInit8         | 39,096        | -                 |
+| accountUnsized8             | 5,952         | -                 |
+| boxedAccountEmptyInit1      | 6,034         | -                 |
+| boxedAccountEmpty1          | 888           | -                 |
+| boxedAccountEmptyInit2      | 10,633        | -                 |
+| boxedAccountEmpty2          | 1,401         | -                 |
+| boxedAccountEmptyInit4      | 19,311        | -                 |
+| boxedAccountEmpty4          | 2,424         | -                 |
+| boxedAccountEmptyInit8      | 37,136        | -                 |
+| boxedAccountEmpty8          | 4,659         | -                 |
+| boxedAccountSizedInit1      | 6,130         | -                 |
+| boxedAccountSized1          | 917           | -                 |
+| boxedAccountSizedInit2      | 10,828        | -                 |
+| boxedAccountSized2          | 1,463         | -                 |
+| boxedAccountSizedInit4      | 19,703        | -                 |
+| boxedAccountSized4          | 2,543         | -                 |
+| boxedAccountSizedInit8      | 37,919        | -                 |
+| boxedAccountSized8          | 4,898         | -                 |
+| boxedAccountUnsizedInit1    | 6,240         | -                 |
+| boxedAccountUnsized1        | 972           | -                 |
+| boxedAccountUnsizedInit2    | 11,048        | -                 |
+| boxedAccountUnsized2        | 1,570         | -                 |
+| boxedAccountUnsizedInit4    | 20,138        | -                 |
+| boxedAccountUnsized4        | 2,768         | -                 |
+| boxedAccountUnsizedInit8    | 38,791        | 🟢 **-9 (0.02%)** |
+| boxedAccountUnsized8        | 5,347         | -                 |
+| boxedInterfaceAccountMint1  | 2,296         | -                 |
+| boxedInterfaceAccountMint2  | 4,129         | -                 |
+| boxedInterfaceAccountMint4  | 7,783         | -                 |
+| boxedInterfaceAccountMint8  | 15,281        | -                 |
+| boxedInterfaceAccountToken1 | 2,023         | -                 |
+| boxedInterfaceAccountToken2 | 3,582         | -                 |
+| boxedInterfaceAccountToken4 | 6,692         | -                 |
+| boxedInterfaceAccountToken8 | 13,098        | -                 |
+| interfaceAccountMint1       | 2,364         | -                 |
+| interfaceAccountMint2       | 5,030         | -                 |
+| interfaceAccountMint4       | 9,803         | -                 |
+| interfaceAccountMint8       | 18,400        | -                 |
+| interfaceAccountToken1      | 2,091         | -                 |
+| interfaceAccountToken2      | 3,948         | -                 |
+| interfaceAccountToken4      | 7,547         | -                 |
+| interface1                  | 1,059         | -                 |
+| interface2                  | 1,479         | -                 |
+| interface4                  | 1,900         | -                 |
+| interface8                  | 3,646         | -                 |
+| program1                    | 1,053         | -                 |
+| program2                    | 1,467         | -                 |
+| program4                    | 1,878         | -                 |
+| program8                    | 3,598         | -                 |
+| signer1                     | 1,018         | -                 |
+| signer2                     | 1,484         | -                 |
+| signer4                     | 1,984         | -                 |
+| signer8                     | 3,880         | -                 |
+| systemAccount1              | 1,072         | -                 |
+| systemAccount2              | 1,590         | -                 |
+| systemAccount4              | 2,195         | -                 |
+| systemAccount8              | 4,305         | -                 |
+| uncheckedAccount1           | 1,014         | -                 |
+| uncheckedAccount2           | 1,475         | -                 |
+| uncheckedAccount4           | 1,965         | -                 |
+| uncheckedAccount8           | 3,841         | -                 |
 
 ### Notable changes
 
@@ -114,95 +114,95 @@ Solana version: 1.16.0
 
 Solana version: 1.16.0
 
-| Instruction                 | Compute Units | +/-                   |
-| --------------------------- | ------------- | --------------------- |
-| accountInfo1                | 1015          | 🔴 **+61 (6.39%)**    |
-| accountInfo2                | 1475          | 🟢 **-92 (5.87%)**    |
-| accountInfo4                | 1964          | 🟢 **-95 (4.61%)**    |
-| accountInfo8                | 3841          | -                     |
-| accountEmptyInit1           | 5817          | 🟢 **-141 (2.37%)**   |
-| accountEmpty1               | 1149          | 🔴 **+59 (5.41%)**    |
-| accountEmptyInit2           | 10402         | 🟢 **-172 (1.63%)**   |
-| accountEmpty2               | 1754          | 🟢 **-98 (5.29%)**    |
-| accountEmptyInit4           | 19508         | -                     |
-| accountEmpty4               | 2540          | 🟢 **-106 (4.01%)**   |
-| accountEmptyInit8           | 37265         | -                     |
-| accountEmpty8               | 5016          | -                     |
-| accountSizedInit1           | 5924          | 🟢 **-139 (2.29%)**   |
-| accountSized1               | 1214          | 🔴 **+79 (6.96%)**    |
-| accountSizedInit2           | 10680         | -                     |
-| accountSized2               | 1873          | 🟢 **-93 (4.73%)**    |
-| accountSizedInit4           | 19970         | -                     |
-| accountSized4               | 2762          | -                     |
-| accountSizedInit8           | 38122         | -                     |
-| accountSized8               | 5353          | -                     |
-| accountUnsizedInit1         | 6052          | 🟢 **-141 (2.28%)**   |
-| accountUnsized1             | 1338          | 🔴 **+95 (7.64%)**    |
-| accountUnsizedInit2         | 10929         | 🟢 **-113 (1.02%)**   |
-| accountUnsized2             | 1778          | 🟢 **-115 (6.08%)**   |
-| accountUnsizedInit4         | 20339         | -                     |
-| accountUnsized4             | 3136          | 🔴 **+32 (1.03%)**    |
-| accountUnsizedInit8         | 39096         | -                     |
-| accountUnsized8             | 5952          | 🟢 **-99 (1.64%)**    |
-| boxedAccountEmptyInit1      | 6034          | 🟢 **-126 (2.05%)**   |
-| boxedAccountEmpty1          | 888           | 🟢 **-88 (9.02%)**    |
-| boxedAccountEmptyInit2      | 10633         | 🟢 **-151 (1.40%)**   |
-| boxedAccountEmpty2          | 1401          | 🟢 **-98 (6.54%)**    |
-| boxedAccountEmptyInit4      | 19311         | -                     |
-| boxedAccountEmpty4          | 2424          | 🟢 **-106 (4.19%)**   |
-| boxedAccountEmptyInit8      | 37136         | -                     |
-| boxedAccountEmpty8          | 4659          | 🟢 **-121 (2.53%)**   |
-| boxedAccountSizedInit1      | 6130          | 🟢 **-126 (2.01%)**   |
-| boxedAccountSized1          | 917           | 🟢 **-86 (8.57%)**    |
-| boxedAccountSizedInit2      | 10828         | 🟢 **-147 (1.34%)**   |
-| boxedAccountSized2          | 1463          | 🟢 **-91 (5.86%)**    |
-| boxedAccountSizedInit4      | 19703         | -                     |
-| boxedAccountSized4          | 2543          | 🟢 **-99 (3.75%)**    |
-| boxedAccountSizedInit8      | 37919         | -                     |
-| boxedAccountSized8          | 4898          | 🟢 **-105 (2.10%)**   |
-| boxedAccountUnsizedInit1    | 6240          | 🟢 **-134 (2.10%)**   |
-| boxedAccountUnsized1        | 972           | 🟢 **-97 (9.07%)**    |
-| boxedAccountUnsizedInit2    | 11048         | 🟢 **-163 (1.45%)**   |
-| boxedAccountUnsized2        | 1570          | 🟢 **-109 (6.49%)**   |
-| boxedAccountUnsizedInit4    | 20138         | 🟢 **-213 (1.05%)**   |
-| boxedAccountUnsized4        | 2768          | 🟢 **-131 (4.52%)**   |
-| boxedAccountUnsizedInit8    | 38800         | -                     |
-| boxedAccountUnsized8        | 5347          | 🟢 **-170 (3.08%)**   |
-| boxedInterfaceAccountMint1  | 2296          | -                     |
-| boxedInterfaceAccountMint2  | 4129          | 🔴 **+76 (1.88%)**    |
-| boxedInterfaceAccountMint4  | 7783          | 🔴 **+245 (3.25%)**   |
-| boxedInterfaceAccountMint8  | 15281         | 🔴 **+582 (3.96%)**   |
-| boxedInterfaceAccountToken1 | 2023          | 🔴 **+286 (16.47%)**  |
-| boxedInterfaceAccountToken2 | 3582          | 🔴 **+654 (22.34%)**  |
-| boxedInterfaceAccountToken4 | 6692          | 🔴 **+1401 (26.48%)** |
-| boxedInterfaceAccountToken8 | 13098         | 🔴 **+2893 (28.35%)** |
-| interfaceAccountMint1       | 2364          | 🟢 **-166 (6.56%)**   |
-| interfaceAccountMint2       | 5030          | 🔴 **+304 (6.43%)**   |
-| interfaceAccountMint4       | 9803          | 🔴 **+372 (3.94%)**   |
-| interfaceAccountMint8       | 18400         | 🔴 **+691 (3.90%)**   |
-| interfaceAccountToken1      | 2091          | 🔴 **+336 (19.15%)**  |
-| interfaceAccountToken2      | 3948          | 🔴 **+737 (22.95%)**  |
-| interfaceAccountToken4      | 7547          | 🔴 **+1541 (25.66%)** |
-| interface1                  | 1059          | 🔴 **+60 (6.01%)**    |
-| interface2                  | 1479          | 🟢 **-95 (6.04%)**    |
-| interface4                  | 1900          | 🟢 **-96 (4.81%)**    |
-| interface8                  | 3646          | -                     |
-| program1                    | 1053          | 🔴 **+54 (5.41%)**    |
-| program2                    | 1467          | 🟢 **-106 (6.74%)**   |
-| program4                    | 1878          | 🟢 **-120 (6.01%)**   |
-| program8                    | 3598          | 🟢 **-53 (1.45%)**    |
-| signer1                     | 1018          | 🔴 **+60 (6.26%)**    |
-| signer2                     | 1484          | 🟢 **-92 (5.84%)**    |
-| signer4                     | 1984          | 🟢 **-95 (4.57%)**    |
-| signer8                     | 3880          | -                     |
-| systemAccount1              | 1072          | 🔴 **+59 (5.82%)**    |
-| systemAccount2              | 1590          | 🟢 **-96 (5.69%)**    |
-| systemAccount4              | 2195          | 🟢 **-103 (4.48%)**   |
-| systemAccount8              | 4305          | -                     |
-| uncheckedAccount1           | 1014          | 🔴 **+61 (6.40%)**    |
-| uncheckedAccount2           | 1475          | 🟢 **-92 (5.87%)**    |
-| uncheckedAccount4           | 1965          | 🟢 **-95 (4.61%)**    |
-| uncheckedAccount8           | 3841          | -                     |
+| Instruction                 | Compute Units | +/-                    |
+| --------------------------- | ------------- | ---------------------- |
+| accountInfo1                | 1,015         | 🔴 **+61 (6.39%)**     |
+| accountInfo2                | 1,475         | 🟢 **-92 (5.87%)**     |
+| accountInfo4                | 1,964         | 🟢 **-95 (4.61%)**     |
+| accountInfo8                | 3,841         | 🟢 **-15 (0.39%)**     |
+| accountEmptyInit1           | 5,817         | 🟢 **-141 (2.37%)**    |
+| accountEmpty1               | 1,149         | 🔴 **+59 (5.41%)**     |
+| accountEmptyInit2           | 10,402        | 🟢 **-172 (1.63%)**    |
+| accountEmpty2               | 1,754         | 🟢 **-98 (5.29%)**     |
+| accountEmptyInit4           | 19,508        | 🟢 **-49 (0.25%)**     |
+| accountEmpty4               | 2,540         | 🟢 **-106 (4.01%)**    |
+| accountEmptyInit8           | 37,265        | 🟢 **-276 (0.74%)**    |
+| accountEmpty8               | 5,016         | 🟢 **-27 (0.54%)**     |
+| accountSizedInit1           | 5,924         | 🟢 **-139 (2.29%)**    |
+| accountSized1               | 1,214         | 🔴 **+79 (6.96%)**     |
+| accountSizedInit2           | 10,680        | 🟢 **-103 (0.96%)**    |
+| accountSized2               | 1,873         | 🟢 **-93 (4.73%)**     |
+| accountSizedInit4           | 19,970        | 🟢 **-5 (0.03%)**      |
+| accountSized4               | 2,762         | 🟢 **-25 (0.90%)**     |
+| accountSizedInit8           | 38,122        | 🟢 **-259 (0.67%)**    |
+| accountSized8               | 5,353         | 🟢 **-6 (0.11%)**      |
+| accountUnsizedInit1         | 6,052         | 🟢 **-141 (2.28%)**    |
+| accountUnsized1             | 1,338         | 🔴 **+95 (7.64%)**     |
+| accountUnsizedInit2         | 10,929        | 🟢 **-113 (1.02%)**    |
+| accountUnsized2             | 1,778         | 🟢 **-115 (6.08%)**    |
+| accountUnsizedInit4         | 20,339        | 🟢 **-156 (0.76%)**    |
+| accountUnsized4             | 3,136         | 🔴 **+32 (1.03%)**     |
+| accountUnsizedInit8         | 39,096        | 🟢 **-323 (0.82%)**    |
+| accountUnsized8             | 5,952         | 🟢 **-99 (1.64%)**     |
+| boxedAccountEmptyInit1      | 6,034         | 🟢 **-126 (2.05%)**    |
+| boxedAccountEmpty1          | 888           | 🟢 **-88 (9.02%)**     |
+| boxedAccountEmptyInit2      | 10,633        | 🟢 **-151 (1.40%)**    |
+| boxedAccountEmpty2          | 1,401         | 🟢 **-98 (6.54%)**     |
+| boxedAccountEmptyInit4      | 19,311        | 🟢 **-189 (0.97%)**    |
+| boxedAccountEmpty4          | 2,424         | 🟢 **-106 (4.19%)**    |
+| boxedAccountEmptyInit8      | 37,136        | 🟢 **-279 (0.75%)**    |
+| boxedAccountEmpty8          | 4,659         | 🟢 **-121 (2.53%)**    |
+| boxedAccountSizedInit1      | 6,130         | 🟢 **-126 (2.01%)**    |
+| boxedAccountSized1          | 917           | 🟢 **-86 (8.57%)**     |
+| boxedAccountSizedInit2      | 10,828        | 🟢 **-147 (1.34%)**    |
+| boxedAccountSized2          | 1,463         | 🟢 **-91 (5.86%)**     |
+| boxedAccountSizedInit4      | 19,703        | 🟢 **-181 (0.91%)**    |
+| boxedAccountSized4          | 2,543         | 🟢 **-99 (3.75%)**     |
+| boxedAccountSizedInit8      | 37,919        | 🟢 **-263 (0.69%)**    |
+| boxedAccountSized8          | 4,898         | 🟢 **-105 (2.10%)**    |
+| boxedAccountUnsizedInit1    | 6,240         | 🟢 **-134 (2.10%)**    |
+| boxedAccountUnsized1        | 972           | 🟢 **-97 (9.07%)**     |
+| boxedAccountUnsizedInit2    | 11,048        | 🟢 **-163 (1.45%)**    |
+| boxedAccountUnsized2        | 1,570         | 🟢 **-109 (6.49%)**    |
+| boxedAccountUnsizedInit4    | 20,138        | 🟢 **-213 (1.05%)**    |
+| boxedAccountUnsized4        | 2,768         | 🟢 **-131 (4.52%)**    |
+| boxedAccountUnsizedInit8    | 38,800        | 🟢 **-318 (0.81%)**    |
+| boxedAccountUnsized8        | 5,347         | 🟢 **-170 (3.08%)**    |
+| boxedInterfaceAccountMint1  | 2,296         | 🟢 **-3 (0.13%)**      |
+| boxedInterfaceAccountMint2  | 4,129         | 🔴 **+76 (1.88%)**     |
+| boxedInterfaceAccountMint4  | 7,783         | 🔴 **+245 (3.25%)**    |
+| boxedInterfaceAccountMint8  | 15,281        | 🔴 **+582 (3.96%)**    |
+| boxedInterfaceAccountToken1 | 2,023         | 🔴 **+286 (16.47%)**   |
+| boxedInterfaceAccountToken2 | 3,582         | 🔴 **+654 (22.34%)**   |
+| boxedInterfaceAccountToken4 | 6,692         | 🔴 **+1,401 (26.48%)** |
+| boxedInterfaceAccountToken8 | 13,098        | 🔴 **+2,893 (28.35%)** |
+| interfaceAccountMint1       | 2,364         | 🟢 **-166 (6.56%)**    |
+| interfaceAccountMint2       | 5,030         | 🔴 **+304 (6.43%)**    |
+| interfaceAccountMint4       | 9,803         | 🔴 **+372 (3.94%)**    |
+| interfaceAccountMint8       | 18,400        | 🔴 **+691 (3.90%)**    |
+| interfaceAccountToken1      | 2,091         | 🔴 **+336 (19.15%)**   |
+| interfaceAccountToken2      | 3,948         | 🔴 **+737 (22.95%)**   |
+| interfaceAccountToken4      | 7,547         | 🔴 **+1,541 (25.66%)** |
+| interface1                  | 1,059         | 🔴 **+60 (6.01%)**     |
+| interface2                  | 1,479         | 🟢 **-95 (6.04%)**     |
+| interface4                  | 1,900         | 🟢 **-96 (4.81%)**     |
+| interface8                  | 3,646         | 🟢 **-5 (0.14%)**      |
+| program1                    | 1,053         | 🔴 **+54 (5.41%)**     |
+| program2                    | 1,467         | 🟢 **-106 (6.74%)**    |
+| program4                    | 1,878         | 🟢 **-120 (6.01%)**    |
+| program8                    | 3,598         | 🟢 **-53 (1.45%)**     |
+| signer1                     | 1,018         | 🔴 **+60 (6.26%)**     |
+| signer2                     | 1,484         | 🟢 **-92 (5.84%)**     |
+| signer4                     | 1,984         | 🟢 **-95 (4.57%)**     |
+| signer8                     | 3,880         | 🟢 **-15 (0.39%)**     |
+| systemAccount1              | 1,072         | 🔴 **+59 (5.82%)**     |
+| systemAccount2              | 1,590         | 🟢 **-96 (5.69%)**     |
+| systemAccount4              | 2,195         | 🟢 **-103 (4.48%)**    |
+| systemAccount8              | 4,305         | 🟢 **-31 (0.71%)**     |
+| uncheckedAccount1           | 1,014         | 🔴 **+61 (6.40%)**     |
+| uncheckedAccount2           | 1,475         | 🟢 **-92 (5.87%)**     |
+| uncheckedAccount4           | 1,965         | 🟢 **-95 (4.61%)**     |
+| uncheckedAccount8           | 3,841         | 🟢 **-14 (0.36%)**     |
 
 ### Notable changes
 
@@ -217,91 +217,91 @@ Solana version: 1.14.16
 | Instruction                 | Compute Units | +/- |
 | --------------------------- | ------------- | --- |
 | accountInfo1                | 954           | N/A |
-| accountInfo2                | 1567          | N/A |
-| accountInfo4                | 2059          | N/A |
-| accountInfo8                | 3856          | N/A |
-| accountEmptyInit1           | 5958          | N/A |
-| accountEmpty1               | 1090          | N/A |
-| accountEmptyInit2           | 10574         | N/A |
-| accountEmpty2               | 1852          | N/A |
-| accountEmptyInit4           | 19557         | N/A |
-| accountEmpty4               | 2646          | N/A |
-| accountEmptyInit8           | 37541         | N/A |
-| accountEmpty8               | 5043          | N/A |
-| accountSizedInit1           | 6063          | N/A |
-| accountSized1               | 1135          | N/A |
-| accountSizedInit2           | 10783         | N/A |
-| accountSized2               | 1966          | N/A |
-| accountSizedInit4           | 19975         | N/A |
-| accountSized4               | 2787          | N/A |
-| accountSizedInit8           | 38381         | N/A |
-| accountSized8               | 5359          | N/A |
-| accountUnsizedInit1         | 6193          | N/A |
-| accountUnsized1             | 1243          | N/A |
-| accountUnsizedInit2         | 11042         | N/A |
-| accountUnsized2             | 1893          | N/A |
-| accountUnsizedInit4         | 20495         | N/A |
-| accountUnsized4             | 3104          | N/A |
-| accountUnsizedInit8         | 39419         | N/A |
-| accountUnsized8             | 6051          | N/A |
-| boxedAccountEmptyInit1      | 6160          | N/A |
+| accountInfo2                | 1,567         | N/A |
+| accountInfo4                | 2,059         | N/A |
+| accountInfo8                | 3,856         | N/A |
+| accountEmptyInit1           | 5,958         | N/A |
+| accountEmpty1               | 1,090         | N/A |
+| accountEmptyInit2           | 10,574        | N/A |
+| accountEmpty2               | 1,852         | N/A |
+| accountEmptyInit4           | 19,557        | N/A |
+| accountEmpty4               | 2,646         | N/A |
+| accountEmptyInit8           | 37,541        | N/A |
+| accountEmpty8               | 5,043         | N/A |
+| accountSizedInit1           | 6,063         | N/A |
+| accountSized1               | 1,135         | N/A |
+| accountSizedInit2           | 10,783        | N/A |
+| accountSized2               | 1,966         | N/A |
+| accountSizedInit4           | 19,975        | N/A |
+| accountSized4               | 2,787         | N/A |
+| accountSizedInit8           | 38,381        | N/A |
+| accountSized8               | 5,359         | N/A |
+| accountUnsizedInit1         | 6,193         | N/A |
+| accountUnsized1             | 1,243         | N/A |
+| accountUnsizedInit2         | 11,042        | N/A |
+| accountUnsized2             | 1,893         | N/A |
+| accountUnsizedInit4         | 20,495        | N/A |
+| accountUnsized4             | 3,104         | N/A |
+| accountUnsizedInit8         | 39,419        | N/A |
+| accountUnsized8             | 6,051         | N/A |
+| boxedAccountEmptyInit1      | 6,160         | N/A |
 | boxedAccountEmpty1          | 976           | N/A |
-| boxedAccountEmptyInit2      | 10784         | N/A |
-| boxedAccountEmpty2          | 1499          | N/A |
-| boxedAccountEmptyInit4      | 19500         | N/A |
-| boxedAccountEmpty4          | 2530          | N/A |
-| boxedAccountEmptyInit8      | 37415         | N/A |
-| boxedAccountEmpty8          | 4780          | N/A |
-| boxedAccountSizedInit1      | 6256          | N/A |
-| boxedAccountSized1          | 1003          | N/A |
-| boxedAccountSizedInit2      | 10975         | N/A |
-| boxedAccountSized2          | 1554          | N/A |
-| boxedAccountSizedInit4      | 19884         | N/A |
-| boxedAccountSized4          | 2642          | N/A |
-| boxedAccountSizedInit8      | 38182         | N/A |
-| boxedAccountSized8          | 5003          | N/A |
-| boxedAccountUnsizedInit1    | 6374          | N/A |
-| boxedAccountUnsized1        | 1069          | N/A |
-| boxedAccountUnsizedInit2    | 11211         | N/A |
-| boxedAccountUnsized2        | 1679          | N/A |
-| boxedAccountUnsizedInit4    | 20351         | N/A |
-| boxedAccountUnsized4        | 2899          | N/A |
-| boxedAccountUnsizedInit8    | 39118         | N/A |
-| boxedAccountUnsized8        | 5517          | N/A |
-| boxedInterfaceAccountMint1  | 2299          | N/A |
-| boxedInterfaceAccountMint2  | 4053          | N/A |
-| boxedInterfaceAccountMint4  | 7538          | N/A |
-| boxedInterfaceAccountMint8  | 14699         | N/A |
-| boxedInterfaceAccountToken1 | 1737          | N/A |
-| boxedInterfaceAccountToken2 | 2928          | N/A |
-| boxedInterfaceAccountToken4 | 5291          | N/A |
-| boxedInterfaceAccountToken8 | 10205         | N/A |
-| interfaceAccountMint1       | 2530          | N/A |
-| interfaceAccountMint2       | 4726          | N/A |
-| interfaceAccountMint4       | 9431          | N/A |
-| interfaceAccountMint8       | 17709         | N/A |
-| interfaceAccountToken1      | 1755          | N/A |
-| interfaceAccountToken2      | 3211          | N/A |
-| interfaceAccountToken4      | 6006          | N/A |
+| boxedAccountEmptyInit2      | 10,784        | N/A |
+| boxedAccountEmpty2          | 1,499         | N/A |
+| boxedAccountEmptyInit4      | 19,500        | N/A |
+| boxedAccountEmpty4          | 2,530         | N/A |
+| boxedAccountEmptyInit8      | 37,415        | N/A |
+| boxedAccountEmpty8          | 4,780         | N/A |
+| boxedAccountSizedInit1      | 6,256         | N/A |
+| boxedAccountSized1          | 1,003         | N/A |
+| boxedAccountSizedInit2      | 10,975        | N/A |
+| boxedAccountSized2          | 1,554         | N/A |
+| boxedAccountSizedInit4      | 19,884        | N/A |
+| boxedAccountSized4          | 2,642         | N/A |
+| boxedAccountSizedInit8      | 38,182        | N/A |
+| boxedAccountSized8          | 5,003         | N/A |
+| boxedAccountUnsizedInit1    | 6,374         | N/A |
+| boxedAccountUnsized1        | 1,069         | N/A |
+| boxedAccountUnsizedInit2    | 11,211        | N/A |
+| boxedAccountUnsized2        | 1,679         | N/A |
+| boxedAccountUnsizedInit4    | 20,351        | N/A |
+| boxedAccountUnsized4        | 2,899         | N/A |
+| boxedAccountUnsizedInit8    | 39,118        | N/A |
+| boxedAccountUnsized8        | 5,517         | N/A |
+| boxedInterfaceAccountMint1  | 2,299         | N/A |
+| boxedInterfaceAccountMint2  | 4,053         | N/A |
+| boxedInterfaceAccountMint4  | 7,538         | N/A |
+| boxedInterfaceAccountMint8  | 14,699        | N/A |
+| boxedInterfaceAccountToken1 | 1,737         | N/A |
+| boxedInterfaceAccountToken2 | 2,928         | N/A |
+| boxedInterfaceAccountToken4 | 5,291         | N/A |
+| boxedInterfaceAccountToken8 | 10,205        | N/A |
+| interfaceAccountMint1       | 2,530         | N/A |
+| interfaceAccountMint2       | 4,726         | N/A |
+| interfaceAccountMint4       | 9,431         | N/A |
+| interfaceAccountMint8       | 17,709        | N/A |
+| interfaceAccountToken1      | 1,755         | N/A |
+| interfaceAccountToken2      | 3,211         | N/A |
+| interfaceAccountToken4      | 6,006         | N/A |
 | interface1                  | 999           | N/A |
-| interface2                  | 1574          | N/A |
-| interface4                  | 1996          | N/A |
-| interface8                  | 3651          | N/A |
+| interface2                  | 1,574         | N/A |
+| interface4                  | 1,996         | N/A |
+| interface8                  | 3,651         | N/A |
 | program1                    | 999           | N/A |
-| program2                    | 1573          | N/A |
-| program4                    | 1998          | N/A |
-| program8                    | 3651          | N/A |
+| program2                    | 1,573         | N/A |
+| program4                    | 1,998         | N/A |
+| program8                    | 3,651         | N/A |
 | signer1                     | 958           | N/A |
-| signer2                     | 1576          | N/A |
-| signer4                     | 2079          | N/A |
-| signer8                     | 3895          | N/A |
-| systemAccount1              | 1013          | N/A |
-| systemAccount2              | 1686          | N/A |
-| systemAccount4              | 2298          | N/A |
-| systemAccount8              | 4336          | N/A |
+| signer2                     | 1,576         | N/A |
+| signer4                     | 2,079         | N/A |
+| signer8                     | 3,895         | N/A |
+| systemAccount1              | 1,013         | N/A |
+| systemAccount2              | 1,686         | N/A |
+| systemAccount4              | 2,298         | N/A |
+| systemAccount8              | 4,336         | N/A |
 | uncheckedAccount1           | 953           | N/A |
-| uncheckedAccount2           | 1567          | N/A |
-| uncheckedAccount4           | 2060          | N/A |
-| uncheckedAccount8           | 3855          | N/A |
+| uncheckedAccount2           | 1,567         | N/A |
+| uncheckedAccount4           | 2,060         | N/A |
+| uncheckedAccount8           | 3,855         | N/A |
 
 ---

+ 10 - 1
tests/bench/bench.json

@@ -2,6 +2,9 @@
   "0.27.0": {
     "solanaVersion": "1.14.16",
     "result": {
+      "binarySize": {
+        "bench": 1118736
+      },
       "computeUnits": {
         "accountInfo1": 954,
         "accountInfo2": 1567,
@@ -96,6 +99,9 @@
   "0.28.0": {
     "solanaVersion": "1.16.0",
     "result": {
+      "binarySize": {
+        "bench": 1153736
+      },
       "computeUnits": {
         "accountInfo1": 1015,
         "accountInfo2": 1475,
@@ -190,6 +196,9 @@
   "unreleased": {
     "solanaVersion": "1.16.0",
     "result": {
+      "binarySize": {
+        "bench": 1153736
+      },
       "computeUnits": {
         "accountInfo1": 1015,
         "accountInfo2": 1475,
@@ -281,4 +290,4 @@
       }
     }
   }
-}
+}

+ 48 - 59
tests/bench/scripts/sync-markdown.ts

@@ -1,80 +1,69 @@
 /** Sync Markdown files in /bench based on the data from bench.json */
 
-import { BenchData, Markdown } from "./utils";
+import { BenchData, BenchResult, Markdown } from "./utils";
 
 (async () => {
   const bench = await BenchData.open();
 
   await BenchData.forEachMarkdown((markdown, fileName) => {
-    if (fileName === "COMPUTE_UNITS.md") {
-      const versions = bench.getVersions();
+    const resultType = fileName
+      .toLowerCase()
+      .replace(".md", "")
+      .replace(/_\w/g, (match) => match[1].toUpperCase()) as keyof BenchResult;
 
-      // On the first version, compare with itself to update it with no changes
-      versions.unshift(versions[0]);
+    const versions = bench.getVersions();
 
-      for (const i in versions) {
-        const currentVersion = versions[i];
-        const nextVersion = versions[+i + 1];
+    // On the first version, compare with itself to update it with no changes
+    versions.unshift(versions[0]);
 
-        if (currentVersion === "unreleased") {
-          return;
-        }
+    for (const i in versions) {
+      const currentVersion = versions[i];
+      if (currentVersion === "unreleased") return;
 
-        const newData = bench.get(nextVersion);
-        const oldData = bench.get(currentVersion);
+      const nextVersion = versions[+i + 1];
+      const newData = bench.get(nextVersion);
+      const oldData = bench.get(currentVersion);
 
-        // Create table
-        const table = Markdown.createTable(
-          "Instruction",
-          "Compute Units",
-          "+/-"
-        );
+      // Create table
+      const table = Markdown.createTable();
 
-        bench.compareComputeUnits(
-          newData.result.computeUnits,
-          oldData.result.computeUnits,
-          ({ ixName, newComputeUnits, oldComputeUnits }) => {
-            if (newComputeUnits === null) {
-              // Deleted instruction
-              return;
-            }
+      bench.compare({
+        newResult: newData.result[resultType],
+        oldResult: oldData.result[resultType],
+        changeCb: ({ name, newValue, oldValue }) => {
+          if (newValue === null) {
+            // Deleted key
+            return;
+          }
 
-            let changeText;
-            if (oldComputeUnits === null) {
-              // New instruction
-              changeText = "N/A";
-            } else {
-              const delta = newComputeUnits - oldComputeUnits;
-              const percentChange = (
-                (newComputeUnits / oldComputeUnits - 1) *
-                100
-              ).toFixed(2);
+          let changeText: string;
+          if (oldValue === null) {
+            // New key
+            changeText = "N/A";
+          } else {
+            const delta = (newValue - oldValue).toLocaleString();
+            const percentChange = ((newValue / oldValue - 1) * 100).toFixed(2);
 
-              if (+percentChange > 0) {
-                changeText = `🔴 **+${delta} (${percentChange}%)**`;
-              } else {
-                changeText = `🟢 **${delta} (${percentChange.slice(1)}%)**`;
-              }
+            if (+percentChange > 0) {
+              changeText = `🔴 **+${delta} (${percentChange}%)**`;
+            } else {
+              changeText = `🟢 **${delta} (${percentChange.slice(1)}%)**`;
             }
-
-            table.insert(ixName, newComputeUnits.toString(), changeText);
-          },
-          (ixName, computeUnits) => {
-            table.insert(
-              ixName,
-              computeUnits.toString(),
-              +i === 0 ? "N/A" : "-"
-            );
           }
-        );
 
-        // Update version data
-        markdown.updateVersion({
-          version: nextVersion,
-          solanaVersion: newData.solanaVersion,
-          table,
-        });
-      }
+          table.insert(name, newValue.toLocaleString(), changeText);
+        },
+        noChangeCb: ({ name, value }) => {
+          table.insert(name, value.toLocaleString(), +i === 0 ? "N/A" : "-");
+        },
+      });
+
+      // Update version data
+      markdown.updateVersion({
+        version: nextVersion,
+        solanaVersion: newData.solanaVersion,
+        table,
+      });
     }
   });
 })();

+ 4 - 0
tests/bench/scripts/sync.ts

@@ -14,6 +14,7 @@ import {
   Toml,
   VersionManager,
   runAnchorTest,
+  spawn,
 } from "./utils";
 
 (async () => {
@@ -75,4 +76,7 @@ import {
       return;
     }
   }
+
+  // Sync markdown files
+  spawn("anchor", ["run", "sync-markdown"]);
 })();

+ 135 - 89
tests/bench/scripts/utils.ts

@@ -15,15 +15,23 @@ type Bench = {
      */
     solanaVersion: Version;
     /** Benchmark results for a version */
-    result: {
-      /** Benchmark result for compute units consumed */
-      computeUnits: ComputeUnits;
-    };
+    result: BenchResult;
   };
 };
 
+/** Benchmark result per version */
+export type BenchResult = {
+  /** Benchmark result for program binary size */
+  binarySize: BinarySize;
+  /** Benchmark result for compute units consumed */
+  computeUnits: ComputeUnits;
+};
+
+/** `program name -> binary size` */
+export type BinarySize = { [programName: string]: number };
+
 /** `instruction name -> compute units consumed` */
-export type ComputeUnits = { [key: string]: number };
+export type ComputeUnits = { [ixName: string]: number };
 
 /**
  * How much of a percentage difference between the current and the previous data
@@ -50,7 +58,7 @@ export class BenchData {
     this.#data = data;
   }
 
-  /** Open the benchmark data file */
+  /** Open the benchmark data file. */
   static async open() {
     let bench: Bench;
     try {
@@ -65,86 +73,92 @@ export class BenchData {
     return new BenchData(bench);
   }
 
-  /** Save the benchmark data file */
+  /** Save the benchmark data file. */
   async save() {
     await fs.writeFile(BenchData.#PATH, JSON.stringify(this.#data, null, 2));
   }
 
-  /** Get the stored results based on version */
+  /** Get the stored results based on version. */
   get(version: Version) {
     return this.#data[version];
   }
 
-  /** Get all versions */
+  /** Get all versions. */
   getVersions() {
     return Object.keys(this.#data) as Version[];
   }
 
-  /** Compare and update compute units changes */
-  compareComputeUnits(
-    newComputeUnitsResult: ComputeUnits,
-    oldComputeUnitsResult: ComputeUnits,
+  /** Compare benchmark changes. */
+  compare<K extends keyof BenchResult>({
+    newResult,
+    oldResult,
+    changeCb,
+    noChangeCb,
+    treshold = 0,
+  }: {
+    /** New bench result */
+    newResult: BenchResult[K];
+    /** Old bench result */
+    oldResult: BenchResult[K];
+    /** Callback to run when there is a change(considering `threshold`) */
     changeCb: (args: {
-      ixName: string;
-      newComputeUnits: number | null;
-      oldComputeUnits: number | null;
-    }) => void,
-    noChangeCb?: (ixName: string, computeUnits: number) => void
-  ) {
+      name: string;
+      newValue: number | null;
+      oldValue: number | null;
+    }) => void;
+    /** Callback to run when there is no change(considering `threshold`) */
+    noChangeCb?: (args: { name: string; value: number }) => void;
+    /** Change threshold percentage(maximum allowed difference between results) */
+    treshold?: number;
+  }) {
     let needsUpdate = false;
+    const executeChangeCb = (...args: Parameters<typeof changeCb>) => {
+      changeCb(...args);
+      needsUpdate = true;
+    };
 
-    const checkIxs = (
-      comparedFrom: ComputeUnits,
-      comparedTo: ComputeUnits,
-      cb: (ixName: string, computeUnits: number) => void
+    const compare = (
+      compareFrom: BenchResult[K],
+      compareTo: BenchResult[K],
+      cb: (name: string, value: number) => void
     ) => {
-      for (const ixName in comparedFrom) {
-        if (comparedTo[ixName] === undefined) {
-          cb(ixName, comparedFrom[ixName]);
+      for (const name in compareFrom) {
+        if (compareTo[name] === undefined) {
+          cb(name, compareTo[name]);
         }
       }
     };
 
-    // New instruction
-    checkIxs(
-      newComputeUnitsResult,
-      oldComputeUnitsResult,
-      (ixName, computeUnits) => {
-        console.log(`New instruction '${ixName}'`);
-        changeCb({
-          ixName,
-          newComputeUnits: computeUnits,
-          oldComputeUnits: null,
-        });
-        needsUpdate = true;
-      }
-    );
+    // New key
+    compare(newResult, oldResult, (name, value) => {
+      console.log(`New key '${name}'`);
+      executeChangeCb({
+        name,
+        newValue: value,
+        oldValue: null,
+      });
+    });
 
-    // Deleted instruction
-    checkIxs(
-      oldComputeUnitsResult,
-      newComputeUnitsResult,
-      (ixName, computeUnits) => {
-        console.log(`Deleted instruction '${ixName}'`);
-        changeCb({
-          ixName,
-          newComputeUnits: null,
-          oldComputeUnits: computeUnits,
-        });
-        needsUpdate = true;
-      }
-    );
+    // Deleted key
+    compare(oldResult, newResult, (name, value) => {
+      console.log(`Deleted key '${name}'`);
+      executeChangeCb({
+        name,
+        newValue: null,
+        oldValue: value,
+      });
+    });
 
     // Compare compute units changes
-    for (const ixName in newComputeUnitsResult) {
-      const oldComputeUnits = oldComputeUnitsResult[ixName];
-      const newComputeUnits = newComputeUnitsResult[ixName];
+    for (const name in newResult) {
+      const oldValue = oldResult[name];
+      const newValue = newResult[name];
 
-      const percentage = THRESHOLD_PERCENTAGE / 100;
-      const oldMaximumAllowedDelta = oldComputeUnits * percentage;
-      const newMaximumAllowedDelta = newComputeUnits * percentage;
+      const percentage = treshold / 100;
+      const oldMaximumAllowedDelta = oldValue * percentage;
+      const newMaximumAllowedDelta = newValue * percentage;
 
-      const delta = newComputeUnits - oldComputeUnits;
+      const delta = newValue - oldValue;
       const absDelta = Math.abs(delta);
 
       if (
@@ -155,31 +169,60 @@ export class BenchData {
         if (process.env.CI) {
           throw new Error(
             [
-              `Compute units for instruction '${ixName}' has changed more than ${THRESHOLD_PERCENTAGE}% but is not saved.`,
+              `Key '${name}' has changed more than ${treshold}% but is not saved.`,
               "Run `anchor test --skip-lint` in tests/bench and commit the changes.",
             ].join(" ")
           );
         }
 
-        console.log(
-          `Compute units change '${ixName}' (${oldComputeUnits} -> ${newComputeUnits})`
-        );
+        console.log(`'${name}' (${oldValue} -> ${newValue})`);
 
-        changeCb({
-          ixName,
-          newComputeUnits,
-          oldComputeUnits,
+        executeChangeCb({
+          name,
+          newValue,
+          oldValue,
         });
-        needsUpdate = true;
       } else {
-        noChangeCb?.(ixName, newComputeUnits);
+        noChangeCb?.({ name, value: newValue });
       }
     }
 
     return { needsUpdate };
   }
 
-  /** Bump benchmark data version to the given version */
+  /** Compare and update benchmark changes. */
+  async update(result: Partial<BenchResult>) {
+    const resultType = Object.keys(result)[0] as keyof typeof result;
+    const newResult = result[resultType]!;
+
+    // Compare and update benchmark changes
+    const version = getVersionFromArgs();
+    const oldResult = this.get(version).result[resultType];
+    const { needsUpdate } = this.compare({
+      newResult,
+      oldResult,
+      changeCb: ({ name, newValue }) => {
+        if (newValue === null) delete oldResult[name];
+        else oldResult[name] = newValue;
+      },
+      treshold: THRESHOLD_PERCENTAGE,
+    });
+
+    if (needsUpdate) {
+      console.log("Updating benchmark files...");
+
+      // Save bench data file
+      // (needs to happen before running the `sync-markdown` script)
+      await this.save();
+
+      // Only update markdown files on `unreleased` version
+      if (version === "unreleased") {
+        spawn("anchor", ["run", "sync-markdown"]);
+      }
+    }
+  }
+
+  /** Bump benchmark data version to the given version. */
   bumpVersion(newVersion: string) {
     if (this.#data[newVersion]) {
       throw new Error(`Version '${newVersion}' already exists!`);
@@ -240,23 +283,23 @@ export class Markdown {
     this.#text = text;
   }
 
-  /** Open the markdown file */
+  /** Open the markdown file. */
   static async open(path: string) {
     const text = await fs.readFile(path, { encoding: "utf8" });
     return new Markdown(path, text);
   }
 
-  /** Create a markdown table */
+  /** Create a markdown table. */
   static createTable(...args: string[]) {
     return new MarkdownTable([args]);
   }
 
-  /** Save the markdown file */
+  /** Save the markdown file. */
   async save() {
     await fs.writeFile(this.#path, this.#text);
   }
 
-  /** Change the version's content with the given `solanaVersion` and `table` */
+  /** Change the version's content with the given `solanaVersion` and `table`. */
   updateVersion(params: {
     version: Version;
     solanaVersion: string;
@@ -274,17 +317,20 @@ export class Markdown {
 
     const tableStartIndex =
       titleStartIndex + md.slice(titleStartIndex).indexOf("|");
+    const tableRowStartIndex =
+      tableStartIndex + md.slice(tableStartIndex).indexOf("\n");
     const tableEndIndex =
       tableStartIndex + md.slice(tableStartIndex).indexOf("\n\n");
 
     this.#text =
       md.slice(0, titleContentStartIndex) +
       `Solana version: ${params.solanaVersion}\n\n` +
+      md.slice(tableStartIndex, tableRowStartIndex - 1) +
       params.table.toString() +
       md.slice(tableEndIndex + 1);
   }
 
-  /** Bump the version to the given version */
+  /** Bump the version to the given version. */
   bumpVersion(newVersion: string) {
     newVersion = `[${newVersion}]`;
     if (this.#text.includes(newVersion)) {
@@ -342,12 +388,12 @@ class MarkdownTable {
     this.insert("-", "-", "-");
   }
 
-  /** Insert a new row to the markdown table */
+  /** Insert a new row to the markdown table. */
   insert(...args: string[]) {
     this.#rows.push(args);
   }
 
-  /** Convert the stored rows to a markdown table */
+  /** Convert the stored rows to a markdown table. */
   toString() {
     return this.#rows.reduce(
       (acc, row) =>
@@ -370,7 +416,7 @@ export class Toml {
     this.#text = text;
   }
 
-  /** Open the TOML file */
+  /** Open the TOML file. */
   static async open(tomlPath: string) {
     tomlPath = path.join(__dirname, tomlPath);
     const text = await fs.readFile(tomlPath, {
@@ -379,12 +425,12 @@ export class Toml {
     return new Toml(tomlPath, text);
   }
 
-  /** Save the TOML file */
+  /** Save the TOML file. */
   async save() {
     await fs.writeFile(this.#path, this.#text);
   }
 
-  /** Replace the value for the given key */
+  /** Replace the value for the given key. */
   replaceValue(
     key: string,
     cb: (previous: string) => string,
@@ -402,7 +448,7 @@ export class LockFile {
   /** Cargo lock file name */
   static #CARGO_LOCK = "Cargo.lock";
 
-  /** Replace the Cargo.lock with the given version's cached lock file */
+  /** Replace the Cargo.lock with the given version's cached lock file. */
   static async replace(version: Version) {
     // Remove Cargo.lock
     try {
@@ -416,7 +462,7 @@ export class LockFile {
     }
   }
 
-  /** Cache the current Cargo.lock in ./locks */
+  /** Cache the current Cargo.lock in `./locks`. */
   static async cache(version: Version) {
     try {
       await fs.rename(this.#CARGO_LOCK, this.#getLockPath(version));
@@ -434,7 +480,7 @@ export class LockFile {
     }
   }
 
-  /** Get the lock file path from the given version */
+  /** Get the lock file path from the given version. */
   static #getLockPath(version: Version) {
     return path.join("locks", `${version}.lock`);
   }
@@ -442,7 +488,7 @@ export class LockFile {
 
 /** Utility class to manage versions */
 export class VersionManager {
-  /** Set the active Solana version with `solana-install init` command */
+  /** Set the active Solana version with `solana-install init` command. */
   static setSolanaVersion(version: Version) {
     const activeVersion = this.#getSolanaVersion();
     if (activeVersion === version) return;
@@ -453,7 +499,7 @@ export class VersionManager {
     });
   }
 
-  /** Get the active Solana version */
+  /** Get the active Solana version. */
   static #getSolanaVersion() {
     // `solana-cli 1.14.16 (src:0fb2ffda; feat:3488713414)\n`
     const result = execSync("solana --version");
@@ -476,12 +522,12 @@ export const getVersionFromArgs = () => {
     : (args[anchorVersionArgIndex + 1] as Version);
 };
 
-/** Run `anchor test` command */
+/** Run `anchor test` command. */
 export const runAnchorTest = () => {
   return spawn("anchor", ["test", "--skip-lint"]);
 };
 
-/** Spawn a blocking process */
+/** Spawn a blocking process. */
 export const spawn = (
   cmd: string,
   args: string[],

+ 19 - 0
tests/bench/tests/binary-size.ts

@@ -0,0 +1,19 @@
+import * as fs from "fs/promises";
+import path from "path";
+
+import { IDL } from "../target/types/bench";
+import { BenchData, BinarySize } from "../scripts/utils";
+
+describe("Binary size", () => {
+  const binarySize: BinarySize = {};
+
+  it(`Measure binary size of program '${IDL.name}'`, async () => {
+    const stat = await fs.stat(path.join("target", "deploy", `${IDL.name}.so`));
+    binarySize[IDL.name] = stat.size;
+  });
+
+  after(async () => {
+    const bench = await BenchData.open();
+    await bench.update({ binarySize });
+  });
+});

+ 2 - 32
tests/bench/tests/compute-units.ts

@@ -9,7 +9,7 @@ import {
   spawn,
 } from "../scripts/utils";
 
-describe(IDL.name, () => {
+describe("Compute units", () => {
   // Configure the client to use the local cluster
   anchor.setProvider(anchor.AnchorProvider.env());
 
@@ -115,8 +115,6 @@ describe(IDL.name, () => {
   };
 
   before(async () => {
-    // TODO: Check Solana version
-
     // Create necessary accounts
     const tokenProgram = token.splTokenProgram({
       provider: anchor.AnchorProvider.local(),
@@ -229,35 +227,7 @@ describe(IDL.name, () => {
   });
 
   after(async () => {
-    // Read the bench data file
     const bench = await BenchData.open();
-
-    // Compare and update compute units changes
-    const version = getVersionFromArgs();
-    const oldComputeUnits = bench.get(version).result.computeUnits;
-    const { needsUpdate } = bench.compareComputeUnits(
-      computeUnits,
-      oldComputeUnits,
-      ({ ixName, newComputeUnits: newValue }) => {
-        if (newValue === null) {
-          delete oldComputeUnits[ixName];
-        } else {
-          oldComputeUnits[ixName] = newValue;
-        }
-      }
-    );
-
-    if (needsUpdate) {
-      console.log("Updating benchmark files...");
-
-      // Save bench data file
-      // (needs to happen before running the `sync-markdown` script)
-      await bench.save();
-
-      // Only update markdown files on `unreleased` version
-      if (version === "unreleased") {
-        spawn("anchor", ["run", "sync-markdown"]);
-      }
-    }
+    await bench.update({ computeUnits });
   });
 });