benchmark: timing pht insert operations

This commit is contained in:
kaldoran authored and Adrien Béraud committed 2016-09-01 18:02:23 -04:00
1 parent 33fae1cb66
commit 041e280bde
4 files changed
+37 -13

No files matched your search

+1
View File
@@ -171,6 +171,7 @@ if __name__ == '__main__':
featureArgs.add_argument('--pht', action='store_true', default=False,
help='Launches PHT benchmark test. '\
'Available args for "-t" are: insert. '\
'Timer available by adding "timer" to "-o" args'\
'Use "-m" option for fixing number of keys to create during the test.')
featureArgs.add_argument('--data-persistence', action='store_true', default=0,
help='Launches data persistence benchmark test. '\
+26 -7
View File
@@ -49,6 +49,24 @@ def random_hash():
"""
return InfoHash(random_str_val(size=40).encode())
def timer(f, *args):
"""
Start a timer which count time taken for execute function f
@param f : Function to time
@type f : function
@param args : Arguments of the function f
@type args : list
@rtype : timer
@return : Time taken by the function f
"""
start = time.time()
f(*args)
return time.time() - start
def reset_before_test(featureTestMethod):
"""
This is a decorator for all test methods needing reset().
@@ -191,7 +209,6 @@ class FeatureTest(object):
def run(self):
raise NotImplementedError('This method must be implemented.')
##################################
# PHT #
##################################
@@ -220,6 +237,7 @@ class PhtTest(FeatureTest):
"""
super(PhtTest, self).__init__(test, workbench)
self._num_keys = opts['num_keys'] if 'num_keys' in opts else 32
self._timer = True if 'timer' in opts else False
def _reset(self):
super(PhtTest, self)._reset()
@@ -309,14 +327,18 @@ class PhtTest(FeatureTest):
for key in keys:
PhtTest.key = key
with FeatureTest.lock:
pht.insert(key, IndexValue(random_hash()), PhtTest.insertDoneCb)
time_taken = timer(pht.insert, key, IndexValue(random_hash()), PhtTest.insertDoneCb)
if self._timer:
DhtNetwork.log('This insert step took : ', time_taken, 'second')
FeatureTest.lock.wait()
# Recover entries now that the trie is complete.
for key in keys:
PhtTest.key = key
with FeatureTest.lock:
pht.lookup(key, PhtTest.lookupCb, PhtTest.lookupDoneCb)
time_taken = timer(pht.lookup, key, PhtTest.lookupCb, PhtTest.lookupDoneCb)
if self._timer:
DhtNetwork.log('This lookup step took : ', time_taken, 'second')
FeatureTest.lock.wait()
all_entries[PhtTest.prefix] = [e.__str__()
@@ -327,7 +349,6 @@ class PhtTest(FeatureTest):
DhtNetwork.log(all_entries[p])
PhtTest.drawTrie(all_entries)
##################################
# DHT #
##################################
@@ -403,7 +424,6 @@ class DhtFeatureTest(FeatureTest):
for n in DhtFeatureTest.foreignNodes:
nodes.add(n)
class PersistenceTest(DhtFeatureTest):
"""
This tests persistence of data on the network.
@@ -748,8 +768,7 @@ class PersistenceTest(DhtFeatureTest):
hashes = []
# Generating considerable amount of values of size 1KB.
# TODO: Utiliser fonction _initialSetOfValues.
# Generating considerable amount of values of size 1KB.
VALUE_SIZE = 1024
NUM_VALUES = self._num_values if self._num_values else 50
values = [Value(random_str_val(size=VALUE_SIZE).encode()) for _ in range(NUM_VALUES)]