From 7dce969eaabb550ad70dd74335b109ef15ee6cc6 Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Wed, 13 Jan 2021 21:06:28 +0000 Subject: [PATCH] added benchmark for neighbor closeness --- .../benchmark-neighbor-closeness.py | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 tests/benchmarks/benchmark-neighbor-closeness.py diff --git a/tests/benchmarks/benchmark-neighbor-closeness.py b/tests/benchmarks/benchmark-neighbor-closeness.py new file mode 100644 index 00000000..25b5ecc1 --- /dev/null +++ b/tests/benchmarks/benchmark-neighbor-closeness.py @@ -0,0 +1,34 @@ +import sys, os +sys.path.append(".") +sys.path.append("src/") +import unittest, uuid +import subprocess +import time + +TEST_DIR = 'testdata/%s-%s' % (uuid.uuid4(), os.path.basename(__file__)) + '/' +print("Test directory:", TEST_DIR) +os.environ["ONIONR_HOME"] = TEST_DIR +from utils import createdirs, identifyhome +from streamfill import identify_neighbors + +onions = [] +p = subprocess.Popen(["scripts/generate-onions.py", '50000'], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE) +for line in iter(p.stdout.readline, b''): + line = line.decode() + onions.append(line.strip()) +p.terminate() + +p = subprocess.Popen(["scripts/generate-onions.py", '1'], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE) +for line in iter(p.stdout.readline, b''): + us = line.decode().strip() +p.terminate() + +start = time.time() +identify_neighbors(us, onions, 5) +print(time.time() - start) + +