Skip to content

Instantly share code, notes, and snippets.

@ssadler
Created April 21, 2017 11:55
Show Gist options
  • Save ssadler/a2dabde429c436f2b8ccd62476585e24 to your computer and use it in GitHub Desktop.
Save ssadler/a2dabde429c436f2b8ccd62476585e24 to your computer and use it in GitHub Desktop.
Quick benchmark of time to get unspent transactions
import sys
from bigchaindb.core import Bigchain
from bigchaindb.models import Transaction, Block
from bigchaindb.common.crypto import generate_key_pair
import time
test_size = int(sys.argv[1])
priv, pub = generate_key_pair()
b = Bigchain()
txs = []
prev_block = 'a'*64
def vote(block):
global prev_block
b.write_vote(b.vote(block.id, prev_block, True))
prev_block=block.id
for i in range(test_size):
tx = Transaction.create([pub], [([pub], i+1)])
block = b.create_block([tx])
b.write_block(block)
vote(block)
txs.append(tx)
for create in txs:
tx = Transaction.transfer(create.to_inputs(), [([pub], 1)], create.id)
block = b.create_block([tx])
b.write_block(block)
vote(block)
times = []
for i in range(10):
start = time.time()
outputs = b.get_outputs_filtered(pub, False)
t = time.time() - start
times.append(t)
print("%.2fms" % (t*1000))
assert len(outputs) == test_size
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment