Performance testing upload/download using AntTP

yes because I got those errors too often I’ve a modded version of the script now that outputs time to error and doesn’t stop the process:

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()
        try:
            await client_mainnet.scratchpad_update(testpad_privatekey, 0, randomdata)
        except:
            update_time = time.time() - start_time
            print(f"error on scratchpad update - time to error: {update_time:.2f} seconds")
            await speedtest(byte_length)
            return
        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:
            try:
                testpad = await client_mainnet.scratchpad_get(ScratchpadAddress.from_hex(testpad_privatekey.public_key().hex()))
            except:
                print('error fetching scratchpad')
                continue
            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())

(copy+pasted in the mods - hope it’s correct - my test didn’t return usable results - but possibly because we were running mods on the same scratchpad in parallel :smiley: )

3 Likes