testpathtree: Add stress tests
Indicative performance on a lightly loaded 3rd Gen Lenovo X1 Carbon:
$ # Timing 1,000,000 executions of the test case, time units are seconds
$ python -m obmc.utils.testpathtree
Depth tests:
1: 6.01530885696
2: 7.11315083504
3: 8.41325497627
4: 9.51180887222
5: 10.7866010666
6: 12.0375499725
7: 13.4880149364
8: 14.7702541351
9: 16.3227319717
10: 17.6581590176
Width tests:
1: 1.19656515121
2: 1.20851492882
4: 1.2031879425
8: 1.19995284081
16: 1.21298193932
32: 1.20965600014
64: 1.20766687393
128: 1.21984100342
256: 1.21412611008
512: 1.21589684486
1024: 1.2073469162
2048: 1.2244079113
4096: 1.21275901794
8192: 1.22486519814
16384: 1.21715903282
32768: 1.21435189247
65536: 1.2201769352
131072: 1.21944999695
262144: 1.21434497833
524288: 1.20947313309
1048576: 1.21527695656
Change-Id: I05aa3fb59ddc2510e22e22a8802e166e2e801bab
Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
diff --git a/obmc/utils/testpathtree.py b/obmc/utils/testpathtree.py
old mode 100644
new mode 100755
index 5fb5fd3..3c68edc
--- a/obmc/utils/testpathtree.py
+++ b/obmc/utils/testpathtree.py
@@ -1,7 +1,6 @@
import unittest
from .pathtree import PathTree
-from pprint import pprint
class PathTreeTest(unittest.TestCase):
def test_set_depth_1(self):
@@ -309,3 +308,45 @@
pt['/a/c'] = None
pt['/b'] = 4
self.assertEquals(set([('/a/b', 2)]), set(pt.dataitems(subtree='/a', depth=1)))
+
+import timeit
+import sys
+
+def depth_stress(pt, k):
+ pt[k] = 1
+ pt[k] = pt[k] + 1
+ del pt[k]
+
+depth_setup = """\
+from __main__ import depth_stress
+from obmc.utils.pathtree import PathTree
+pt = PathTree()
+key = '/' + '/'.join(['a'] * {})
+"""
+
+def width_stress(pt, k):
+ pt.get_children(k)
+
+width_setup = """\
+from __main__ import width_stress
+from obmc.utils.pathtree import PathTree
+pt = PathTree()
+for i in range(0, {}):
+ pt["/{}/a".format(i)] = i
+key = '/0/a'
+"""
+
+if __name__ == "__main__":
+ print("Depth tests:")
+ for depth in range(1, 11):
+ setup = depth_setup.format(depth)
+ stmt = "depth_stress(pt, key)"
+ time = timeit.timeit(stmt, setup=setup)
+ print("\t{}: {}".format(depth, time))
+ print
+ print("Width tests:")
+ for width in map(lambda x: 2 ** x, range(0, 21)):
+ setup = width_setup.format(width, "{}")
+ stmt = "width_stress(pt, key)"
+ time = timeit.timeit(stmt, setup=setup)
+ print("\t{}: {}".format(width, time))