Skip to content

Instantly share code, notes, and snippets.

@sprt
Created March 21, 2016 22:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sprt/3fb6d2f5d4ea5b206d02 to your computer and use it in GitHub Desktop.
Save sprt/3fb6d2f5d4ea5b206d02 to your computer and use it in GitHub Desktop.
import time
import stem.descriptor
import sys
def measure_average_relays_exit(path):
start_time = time.time()
total_relays, exits, consensuses = 0, 0, 0
for consensus in stem.descriptor.parse_file(path, document_handler=stem.descriptor.DocumentHandler.DOCUMENT):
for desc in consensus.routers.values():
if 'Exit' in desc.flags:
exits += 1
total_relays += 1
consensuses += 1
runtime = time.time() - start_time
print("Finished measure_average_relays_exit('%s')" % path)
print(' Total time: %i seconds' % runtime)
print(' Processed %i consensuses with %i router status entries' % (consensuses, total_relays))
print(' Total exits: %i (%0.2f%%)' % (exits, float(exits) / total_relays))
print(' Time per consensus: %0.5f seconds' % (runtime / consensuses))
print('')
measure_average_relays_exit(sys.argv[1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment