Back to index

plone3  3.1.7
timeBreadCrumbs.py
Go to the documentation of this file.
00001 import timeit
00002 
00003 from Testing.makerequest import makerequest
00004 from AccessControl.SecurityManagement import newSecurityManager
00005 from AccessControl.SecurityManager import setSecurityPolicy
00006 from Products.CMFCore.tests.base.security import PermissiveSecurityPolicy
00007 from Products.CMFCore.tests.base.security import OmnipotentUser
00008 
00009 from Products.Archetypes.tests.utils import populateFolder
00010 from Products.CMFPlone.browser import navigation
00011 
00012 def setup(app, path):
00013     _policy = PermissiveSecurityPolicy()
00014     _oldpolicy = setSecurityPolicy(_policy)
00015     newSecurityManager(None, OmnipotentUser().__of__(app.acl_users))
00016     site = app.unrestrictedTraverse(path)
00017     populateFolder(site, 'Folder', 'Document')
00018     return site
00019 
00020 if __name__ == '__main__':
00021     # run this under "zopectl run misc.py /path/to/Plone"
00022     import sys
00023 
00024     app = makerequest(app)
00025     site = setup(app, sys.argv[1])
00026     request = site.REQUEST
00027 
00028     obj = site.unrestrictedTraverse('folder2/folder22/folder222/doc2222')
00029 
00030     def catalog():
00031         return navigation.CatalogNavigationBreadcrumbs(
00032             obj, request).breadcrumbs()
00033 
00034     def physical():
00035         return navigation.PhysicalNavigationBreadcrumbs(
00036             obj, request).breadcrumbs()
00037 
00038     times = int(sys.argv[2])
00039 
00040     timer = timeit.Timer('catalog()', 'from __main__ import catalog')
00041     print 'catalog-based:', timer.timeit(times)
00042 
00043     timer = timeit.Timer('physical()', 'from __main__ import physical')
00044     print 'physical-based:', timer.timeit(times)