Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions benchmarks/web3/_utils/params.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
# Shared parameterizations and real-world data for microbenchmarks
# All data below is based on real mainnet-style values or representative realistic examples.

# Shared 32-byte hash
HASH32 = "0x5e1d3a76fbf824220e1c5e0c2e5e7e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e"

# Transaction dict (mainnet-style)
TX_DICT = {
"from": "0x742d35Cc6634C0532925a3b844Bc454e4438f44e",
"to": "0x53d284357ec70cE289D6D64134DfAc8E511c8a3D",
"from": "0xFEB4acf3df3cDEA7399794D0869ef76A6EfAff52",
"to": "0xdeadbeef0000000000000000000000000000000000",
"value": 1000000000000000000,
"gas": 21000,
"data": "0x",
Expand All @@ -21,14 +25,14 @@
],
"data": "0x00000000000000000000000000000000000000000000000000000000000003e8",
"blockNumber": 12345678,
"transactionHash": "0x5e1d3a76fbf824220e1c5e0c2e5e7e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1",
"transactionHash": HASH32,
"logIndex": 0,
}

# Block dict (mainnet-style, minimal for formatter)
BLOCK_DICT = {
"number": 12345678,
"hash": "0x5e1d3a76fbf824220e1c5e0c2e5e7e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1",
"hash": HASH32,
"transactions": [TX_DICT, TX_DICT],
"logs": [LOG_ENTRY, LOG_ENTRY],
"miner": "0x829BD824B016326A401d083B33D092293333A830",
Expand All @@ -41,7 +45,7 @@
"blockHash": BLOCK_DICT["hash"],
"blockNumber": BLOCK_DICT["number"],
"transactionIndex": 0,
"transactionHash": TX_DICT["from"],
"transactionHash": HASH32,
"cumulativeGasUsed": 21000,
"status": 1,
"gasUsed": 21000,
Expand Down
57 changes: 28 additions & 29 deletions benchmarks/web3/_utils/test_method_formatters_benchmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,15 @@
from faster_web3.types import RPCEndpoint
from pytest_codspeed import BenchmarkFixture

from benchmarks.web3._utils.params import BLOCK_DICT, FEE_HISTORY_DICT, HASH32, LOG_ENTRY, RECEIPT_DICT, TX_DICT

def run_1000(fn, *args):
for _ in range(1000):
fn(*args)


# --- SYSTEMATIC BENCHMARKS FOR PYTHONIC_RESULT_FORMATTERS ---

# NOTE: These are explicit, non-parameterized, one-per-key test stubs for both web3 and faster_web3.
# All data below is based on real mainnet-style values or representative realistic examples.

TX_DATA = {
"hash": "0xfaceb00c1234567890b00b7be2feedbeefcafe1234567890deadbeefcafebaba",
"nonce": "0x42",
"blockHash": "0x5e1d3a76fbf824220e3d1e4b8b1c1b6b1c1b6b1c1b6b1c1b6b1c1b6b1c1b6b1c",
"blockNumber": "0x1337",
"transactionIndex": "0x0",
"from": "0xFEB4acf3df3cDEA7399794D0869ef76A6EfAff52",
"to": "0xdeadbeef0000000000000000000000000000000000",
"value": "0x1234",
"gas": "0x5208",
"gasPrice": "0x3b9aca00",
"input": "0x",
}


# PYTHONIC_REQUEST_FORMATTERS

Expand All @@ -46,8 +30,8 @@ def run_1000(fn, *args):
"eth_getTransactionByBlockNumberAndIndex": ("latest", "0x0"),
"eth_getRawTransactionByBlockNumberAndIndex": ("latest", "0x0"),
"eth_getUncleByBlockNumberAndIndex": ("latest", "0x0"),
"eth_getRawTransactionByBlockHashAndIndex": ("0xabc", "0x0"),
"eth_getUncleByBlockHashAndIndex": ("0xabc", "0x0"),
"eth_getRawTransactionByBlockHashAndIndex": (HASH32, "0x0"),
"eth_getUncleByBlockHashAndIndex": (HASH32, "0x0"),
"eth_getBlockByNumber": ("latest", True),
"eth_getCode": ("0x742d35Cc6634C0532925a3b844Bc454e4438f44e", "latest"),
"eth_getTransactionCount": ("0x742d35Cc6634C0532925a3b844Bc454e4438f44e", "latest"),
Expand All @@ -56,23 +40,20 @@ def run_1000(fn, *args):
"eth_newFilter": ({"address": "0x742d35Cc6634C0532925a3b844Bc454e4438f44e"},),
}


@pytest.mark.parametrize("endpoint", list(REQUEST_DATA))
def test_PYTHONIC_REQUEST_FORMATTERS(
benchmark: BenchmarkFixture, endpoint: RPCEndpoint
) -> None:
f = web3._utils.method_formatters.PYTHONIC_REQUEST_FORMATTERS[endpoint]
benchmark(run_1000, f, REQUEST_DATA[endpoint])


@pytest.mark.parametrize("endpoint", list(REQUEST_DATA))
def test_faster_PYTHONIC_REQUEST_FORMATTERS(
benchmark: BenchmarkFixture, endpoint: RPCEndpoint
) -> None:
f = faster_web3._utils.method_formatters.PYTHONIC_REQUEST_FORMATTERS[endpoint]
benchmark(run_1000, f, REQUEST_DATA[endpoint])


# Realistic RLP-encoded proof nodes (hex, plausible structure)
PROOF_NODE_1 = (
"0xf90211a0b3c4d5e6f7a8b9c0d1e2f3a4b5c6d7e8f9a0b1c2d3e4f5a6b7c8d9e0f1a2"
Expand All @@ -87,6 +68,10 @@ def test_faster_PYTHONIC_REQUEST_FORMATTERS(
"f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6"
)

TRACE = {"action": {}, "result": {}, "blockHash": HASH32, "blockNumber": 1, "transactionHash": HASH32}

TRACE_RESPONSE = {"trace": [TRACE] * 50, "output": "0x", "transactionHash": HASH32}

RESULT_DATA = {
"eth_accounts": [
"0x742d35Cc6634C0532925a3b844Bc454e4438f44e",
Expand Down Expand Up @@ -124,8 +109,8 @@ def test_faster_PYTHONIC_REQUEST_FORMATTERS(
"eth_sign": "0x2c6401ff0c2b6a1c1b6b1c1b6b1c1b6b1c1b6b1c1b6b1c1b6b1c1b6b1c1b6b1c1",
"eth_sendTransaction": "0xfeedbabe1234567890cafebabe1234567890feedbabe1234567890cafebabe12",
"eth_signTypedData": "0x1c6401ff0c2b6a1c1b6b1c1b6b1c1b6b1c1b6b1c1b6b1c1b6b1c1b6b1c1b6b1c1",
"eth_getRawTransactionByHash": "0x5e1d3a76fbf824220e3d1e4b8b1c1b6b1c1b6b1c1b6b1c1b6b1c1b6b1c1b6b1c1",
"eth_getTransactionByHash": TX_DATA,
"eth_getRawTransactionByHash": HASH32,
"eth_getTransactionByHash": TX_DICT,
"eth_getUncleCountByBlockHash": "0x2",
"eth_getUncleCountByBlockNumber": "0x2",
"eth_getStorageAt": "0x0000000000000000000000000000000000000000000000000000000000000000",
Expand All @@ -139,10 +124,10 @@ def test_faster_PYTHONIC_REQUEST_FORMATTERS(
"storageHash": "0x5e1d3a76fbf824220e3d1e4b8b1c1b6b1c1b6b1c1b6b1c1b6b1c1b6b1c1b6b1",
"storageProof": [],
},
"eth_getTransactionByBlockHashAndIndex": TX_DATA,
"eth_getTransactionByBlockNumberAndIndex": TX_DATA,
"eth_getTransactionByBlockHashAndIndex": TX_DICT,
"eth_getTransactionByBlockNumberAndIndex": TX_DICT,
"eth_subscribe": {
"result": "0x5e1d3a76fbf824220e3d1e4b8b1c1b6b1c1b6b1c1b6b1c1b6b1c1b6b1c1b6b1c1"
"result": HASH32
},
"eth_simulateV1": [
{
Expand Down Expand Up @@ -180,17 +165,31 @@ def test_faster_PYTHONIC_REQUEST_FORMATTERS(
"to": "0x53d284357ec70cE289D6D64134DfAc8E511c8a3D",
"value": "0x8ac7230489e80000",
},
"eth_feeHistory": FEE_HISTORY_DICT,
"eth_getBlockByHash": BLOCK_DICT,
"eth_getBlockByNumber": BLOCK_DICT,
"eth_getBlockReceipts": [RECEIPT_DICT],
"eth_getFilterChanges": [LOG_ENTRY],
"eth_getFilterLogs": [LOG_ENTRY],
"eth_getLogs": [LOG_ENTRY],
"eth_getTransactionReceipt": RECEIPT_DICT,
"eth_signTransaction": TX_DICT,
"trace_block": [TRACE] * 1000,
"trace_transaction": [TRACE] * 50,
"trace_filter": [TRACE] * 2000,
"trace_rawTransaction": TRACE_RESPONSE,
"trace_replayTransaction": TRACE_RESPONSE,
"trace_replayBlockTransactions": TRACE_RESPONSE,
"trace_call": {"from": "0x742d35Cc6634C0532925a3b844Bc454e4438f44e"},
}


@pytest.mark.parametrize("endpoint", list(RESULT_DATA))
def test_PYTHONIC_RESULT_FORMATTERS(
benchmark: BenchmarkFixture, endpoint: RPCEndpoint
) -> None:
f = web3._utils.method_formatters.PYTHONIC_RESULT_FORMATTERS[endpoint]
benchmark(run_1000, f, RESULT_DATA[endpoint])


@pytest.mark.parametrize("endpoint", list(RESULT_DATA))
def test_faster_PYTHONIC_RESULT_FORMATTERS(
benchmark: BenchmarkFixture, endpoint: RPCEndpoint
Expand Down
Loading