Performance testing upload/download using AntTP

import asyncio
import time
from autonomi_client import SecretKey, Client, ScratchpadAddress
from secrets import token_bytes


async def main() -> None:
    client_mainnet = await Client.init()
    testpad_privatekey = SecretKey.from_hex("3a728f71282bd68fcbc6da9e335b46c1122e30eb4dc1ab4ba5c96ef65d365f47")

    async def speedtest(byte_length: int) -> None:
        randomdata: bytes = token_bytes(byte_length)
        start_time: float = time.time()
        await client_mainnet.scratchpad_update(testpad_privatekey, 0, randomdata)
        update_time: float = time.time() - start_time
        print(f"Scratchpad-Update time: {update_time:.2f} seconds")

        tmp: int = 1
        start_time = time.time()
        while True:
            testpad = await client_mainnet.scratchpad_get(
                ScratchpadAddress.from_hex(testpad_privatekey.public_key().hex())
            )
            content: bytes = testpad.decrypt_data(testpad_privatekey)
            if content == randomdata:
                population_time: float = time.time() - start_time
                print(f"population time: {population_time:.2f} seconds")
                print(f"iterations: {tmp} - content: {content[:10]}...")
                break
            tmp += 1

    for _ in range(10):
        await speedtest(500)
        print()


if __name__ == "__main__":
    asyncio.run(main())

you can write this into a speedtest.py file - but you need a python environment with installed lib autonomi-client (pip install autonomi-client) to run it with python speedtest.py / python3 speediest.py

5 Likes