Last active
August 4, 2026 22:18
-
-
Save l0rinc/c3231e287cacfdefd100dbf95cd0c3ad to your computer and use it in GitHub Desktop.
Time large mempool-only gettxspendingprevout requests
This file contains hidden or 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
| #!/usr/bin/env python3 | |
| """Time large mempool-only gettxspendingprevout requests.""" | |
| from statistics import median | |
| from time import perf_counter | |
| from test_framework.test_framework import BitcoinTestFramework | |
| from test_framework.util import assert_equal | |
| class GetTxSpendingPrevoutQuadraticTest(BitcoinTestFramework): | |
| def add_options(self, parser): | |
| parser.add_argument("--counts", default="8000,16000,32000,64000,128000", help="comma-separated request sizes") | |
| parser.add_argument("--repeats", type=int, default=3, help="timed calls per request size") | |
| def set_test_params(self): | |
| self.num_nodes = 1 | |
| self.setup_clean_chain = True | |
| self.rpc_timeout = 600 | |
| def run_test(self): | |
| node = self.nodes[0] | |
| call_rpc = node.gettxspendingprevout | |
| outpoint = {"txid": "00" * 32, "vout": 0} | |
| counts = tuple(int(count) for count in self.options.counts.split(",")) | |
| assert counts and all(count > 0 for count in counts) | |
| assert self.options.repeats > 0 | |
| # Monkey-patch the RPC dispatcher with a count-based caller. | |
| node.gettxspendingprevout = lambda count: call_rpc([outpoint] * count, mempool_only=True) | |
| node.gettxspendingprevout(1) | |
| previous = None | |
| for count in counts: | |
| samples = [] | |
| for _ in range(self.options.repeats): | |
| start = perf_counter() | |
| result = node.gettxspendingprevout(count) | |
| samples.append(perf_counter() - start) | |
| assert_equal(len(result), count) | |
| del result | |
| elapsed = median(samples) | |
| ratio = "-" if previous is None else f"{elapsed / previous:.2f}x" | |
| self.log.info( | |
| f"{count:>6} prevouts: median {elapsed:.3f}s, " | |
| f"range {min(samples):.3f}-{max(samples):.3f}s, " | |
| f"{elapsed / count * 1_000_000:.1f} us/prevout, previous ratio {ratio}" | |
| ) | |
| previous = elapsed | |
| if __name__ == "__main__": | |
| GetTxSpendingPrevoutQuadraticTest(__file__).main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment