Commit 08569a57 authored by Tatuya Kamada's avatar Tatuya Kamada

Test: Add a test to check HBTreeFolder2 GET performace.

parent e89d10aa
......@@ -15,16 +15,20 @@
import random
import unittest
import ZODB
import Testing
from Testing import ZopeTestCase
import Zope2
from Products.HBTreeFolder2.HBTreeFolder2 \
import HBTreeFolder2, ExhaustedUniqueIdsError
from OFS.ObjectManager import BadRequestException
from OFS.Folder import Folder
from Acquisition import aq_base
import timeit
from textwrap import dedent
from Products.ERP5Type.tests.backportUnittest import expectedFailure
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
class HBTreeFolder2Tests(unittest.TestCase):
class HBTreeFolder2Tests(ERP5TypeTestCase):
def getBase(self, ob):
# This is overridden in subclasses.
......@@ -226,6 +230,82 @@ class HBTreeFolder2Tests(unittest.TestCase):
id_list.remove(i)
h._delOb(i)
@expectedFailure
def testPerformanceInDepth(self):
"""
Check HBTreeFolder2 GET performance with the depth and the number of
documents.
"""
init_1 = dedent("""
from Products.HBTreeFolder2.HBTreeFolder2 import HBTreeFolder2
from Products.CMFDefault.File import File
h_depth_1 = HBTreeFolder2()
#from BTrees.OOBTree import OOBTree
#h_depth_1 = OOBTree()
for i in xrange(%d):
id = str(i)
h_depth_1[id] = File(id)
""")
init_2 = dedent("""
from Products.HBTreeFolder2.HBTreeFolder2 import HBTreeFolder2
from Products.CMFDefault.File import File
h_depth_2 = HBTreeFolder2()
#from BTrees.OOBTree import OOBTree
#h_depth_2 = OOBTree()
for i in xrange(%d / 100):
for j in xrange(100):
id = "-".join(map(str,(i,j)))
h_depth_2[id] = File(id)
""")
init_3 = dedent("""
from Products.HBTreeFolder2.HBTreeFolder2 import HBTreeFolder2
from Products.CMFDefault.File import File
h_depth_3 = HBTreeFolder2()
#from BTrees.OOBTree import OOBTree
#h_depth_3 = OOBTree()
for i in xrange(%d / (100 * 10)):
for j in xrange(100):
for k in xrange(10):
id = "-".join(map(str, (i, j, k)))
h_depth_3[id] = File(id)
""")
N = 1000
# measure 100 times of each test
t1 = timeit.Timer("h_depth_1['555']", init_1 % N).timeit(100)
t2 = timeit.Timer("h_depth_2['5-55']", init_2 % N).timeit(100)
t3 = timeit.Timer("h_depth_3['0-55-5']", init_3 % N).timeit(100)
ZopeTestCase._print("\nN = 1000\n")
ZopeTestCase._print("L1=%s\tL2=%s\tL3=%s" % (t1, t2, t3))
N = 10000 # 10 times bigger than previous test
# measure 100 times of each test
t2_1 = timeit.Timer("h_depth_1['5555']", init_1 % N).timeit(100)
t2_2 = timeit.Timer("h_depth_2['55-55']", init_2 % N).timeit(100)
t2_3 = timeit.Timer("h_depth_3['5-55-5']", init_3 % N).timeit(100)
ZopeTestCase._print("\nN = 10000\n")
ZopeTestCase._print("L1'=%s\tL2'=%s\tL3'=%s" % (t2_1, t2_2, t2_3))
N = 100000 # 10 times bigger than pevious test
t3_1 = timeit.Timer("h_depth_1['22222']", init_1 % N).timeit(100)
t3_2 = timeit.Timer("h_depth_2['222-22']", init_2 % N).timeit(100)
t3_3 = timeit.Timer("h_depth_3['22-22-2']", init_3 % N).timeit(100)
ZopeTestCase._print("\nN = 100000\n")
ZopeTestCase._print("L1''=%s\tL2''=%s\tL3''=%s" % (t3_1, t3_2, t3_3))
# These assert are should be True, but right now those are not passed
# assert that L2 is faster than L1, because the bottom node is smaller
self.assertTrue(t1 > t2)
self.assertTrue(t2_1 > t2_2)
self.assertTrue(t3_1 > t3_2)
# assert that L3 is faster than L2, because the bottom node is smaller
self.assertTrue(t2 > t3)
self.assertTrue(t2_2 > t2_3)
self.assertTrue(t3_2 > t3_3)
class TrojanKey:
"""Pretends to be a consistent, immutable, humble citizen...
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment