Created
March 21, 2016 22:39
-
-
Save sprt/3fb6d2f5d4ea5b206d02 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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