Skip to content
Closed
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
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ commands=
basepython=python
commands=
python {toxinidir}/web3/tools/benchmark/main.py --num-calls 5
python {toxinidir}/web3/tools/benchmark/main.py --num-calls 50
python {toxinidir}/web3/tools/benchmark/main.py --num-calls 100
python {toxinidir}/web3/tools/benchmark/main.py --num-calls 25
python {toxinidir}/web3/tools/benchmark/main.py --num-calls 70

[common-wheel-cli]
deps=wheel
Expand Down
28 changes: 11 additions & 17 deletions web3/tools/benchmark/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,26 +81,20 @@ async def build_async_w3_http(endpoint_uri: str) -> Web3:


def sync_benchmark(func: Callable[..., Any], n: int) -> Union[float, str]:
try:
starttime = timeit.default_timer()
for _ in range(n):
func()
endtime = timeit.default_timer()
execution_time = endtime - starttime
return execution_time
except Exception:
return "N/A"
starttime = timeit.default_timer()
for _ in range(n):
func()
endtime = timeit.default_timer()
execution_time = endtime - starttime
return execution_time


async def async_benchmark(func: Callable[..., Any], n: int) -> Union[float, str]:
try:
starttime = timeit.default_timer()
for result in asyncio.as_completed([func() for _ in range(n)]):
await result
execution_time = timeit.default_timer() - starttime
return execution_time
except Exception:
return "N/A"
starttime = timeit.default_timer()
for result in asyncio.as_completed([func() for _ in range(n)]):
await result
execution_time = timeit.default_timer() - starttime
return execution_time


def unlocked_account(w3: "Web3") -> ChecksumAddress:
Expand Down