Skip to content

Instantly share code, notes, and snippets.

@hayorov
Last active May 13, 2019 16:42
Show Gist options
  • Save hayorov/91f5a30fcb769ca8d4dfca2ac6c43eda to your computer and use it in GitHub Desktop.
Save hayorov/91f5a30fcb769ca8d4dfca2ac6c43eda to your computer and use it in GitHub Desktop.
import time
import logging
from web3 import Web3

web3 = Web3(Web3.HTTPProvider('https://nd-483-012-860.p2pify.com'))  # your node

def profile(func):
    def wrap(*args, **kwargs):
        started_at = time.time()
        result = func(*args, **kwargs)
        return (time.time() - started_at)  * 1000
    return wrap
        
from random import randint

@profile
def get_random_block():
    web3.eth.getBlock(randint(0,  7752319))

responses_list = []

for request in range(1000):
    responses_list.append(get_random_block())
    time.sleep(randint(0,  1000)/1000)
from numpy import percentile
percentile(responses_list, 90)
86.49110794067383

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment