massload.py :  » Database » SQLAlchemy » SQLAlchemy-0.6.0 » test » perf » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Database » SQLAlchemy 
SQLAlchemy » SQLAlchemy 0.6.0 » test » perf » massload.py
import time
#import sqlalchemy.orm.attributes as attributes
from sqlalchemy import *
from sqlalchemy.orm import *
from sqlalchemy.test import *

"""

we are testing session.expunge() here, also that the attributes and unitofwork
packages dont keep dereferenced stuff hanging around.

for best results, dont run with sqlite :memory: database, and keep an eye on
top while it runs
"""

NUM = 2500

class LoadTest(TestBase, AssertsExecutionResults):
    @classmethod
    def setup_class(cls):
        global items, meta
        meta = MetaData(testing.db)
        items = Table('items', meta,
            Column('item_id', Integer, primary_key=True),
            Column('value', String(100)))
        items.create()
    @classmethod
    def teardown_class(cls):
        items.drop()
    def setup(self):
        for x in range(1,NUM/500+1):
            l = []
            for y in range(x*500-500 + 1, x*500 + 1):
                l.append({'item_id':y, 'value':'this is item #%d' % y})
            items.insert().execute(*l)

    def testload(self):
        class Item(object):pass

        m = mapper(Item, items)
        sess = create_session()
        now = time.time()
        query = sess.query(Item)
        for x in range (1,NUM/100):
            # this is not needed with cpython which clears non-circular refs immediately
            #gc_collect()
            l = query.filter(items.c.item_id.between(x*100 - 100 + 1, x*100)).all()
            assert len(l) == 100
            print "loaded ", len(l), " items "
            # modifying each object will ensure that the objects get placed in the "dirty" list
            # and will hang around until expunged
            #for a in l:
            #    a.value = 'changed...'
            #assert len(objectstore.get_session().dirty) == len(l)
            #assert len(objectstore.get_session().identity_map) == len(l)
            #assert len(attributes.managed_attributes) == len(l)
            #print len(objectstore.get_session().dirty)
            #print len(objectstore.get_session().identity_map)
            #objectstore.expunge(*l)
        total = time.time() -now
        print "total time ", total


www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.