Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/usr/bin/env python
import timeit
def multiply(x):
return x * 10
def test00(r=5):
msg = tuple(x for x in range(r))
uncles_hashes = map(
multiply,
(x for x in msg)
)
transaction_roots_and_trie_data = map(
multiply,
(x for x in msg)
)
body_bundles = tuple(zip(msg, transaction_roots_and_trie_data, uncles_hashes))
return body_bundles
def test01(r=5):
msg = tuple(x for x in range(r))
uncles_hashes = map(
multiply,
tuple(x for x in msg)
)
transaction_roots_and_trie_data = map(
multiply,
tuple(x for x in msg)
)
body_bundles = tuple(zip(msg, transaction_roots_and_trie_data, uncles_hashes))
return body_bundles
def test10(r=5):
msg = tuple(x for x in range(r))
uncles_hashes = tuple(map(
multiply,
(x for x in msg)
))
transaction_roots_and_trie_data = tuple(map(
multiply,
(x for x in msg)
))
body_bundles = tuple(zip(msg, transaction_roots_and_trie_data, uncles_hashes))
return body_bundles
def test11(r=5):
msg = tuple(x for x in range(r))
uncles_hashes = tuple(map(
multiply,
tuple(x for x in msg)
))
transaction_roots_and_trie_data = tuple(map(
multiply,
tuple(x for x in msg)
))
body_bundles = tuple(zip(msg, transaction_roots_and_trie_data, uncles_hashes))
return body_bundles
nmsgelems = 500 # default is 5
ntimes = 1_000_000 # default is 1 million
print('test00:', timeit.timeit('test00(nmsgelems)', number=ntimes, globals=globals()))
print('test01:', timeit.timeit('test01(nmsgelems)', number=ntimes, globals=globals()))
print('test10:', timeit.timeit('test10(nmsgelems)', number=ntimes, globals=globals()))
print('test11:', timeit.timeit('test11(nmsgelems)', number=ntimes, globals=globals()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment