File: masscreate.py

package info (click to toggle)
sqlalchemy 0.6.3-3%2Bsqueeze1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 10,744 kB
  • ctags: 15,132
  • sloc: python: 93,431; ansic: 787; makefile: 137; xml: 17
file content (39 lines) | stat: -rw-r--r-- 1,067 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# times how long it takes to create 26000 objects
import testenv; testenv.simple_setup()

from sqlalchemy.orm import attributes
import time

manage_attributes = True
init_attributes = manage_attributes and True

class User(object):
    pass
class Address(object):
    pass

if manage_attributes:
    attributes.register_attribute(User, 'id', False, False)
    attributes.register_attribute(User, 'name', False, False)
    attributes.register_attribute(User, 'addresses', True, False, trackparent=True)
    attributes.register_attribute(Address, 'email', False, False)

now = time.time()
for i in range(0,130):
    u = User()
    if init_attributes:
        attributes.manage(u)
    u.id = i
    u.name = "user " + str(i)
    if not manage_attributes:
        u.addresses = []
    for j in range(0,200):
        a = Address()
        if init_attributes:
            attributes.manage(a)
        a.email = 'foo@bar.com'
        u.addresses.append(a)
#    print len(managed_attributes)
#    managed_attributes.clear()
total = time.time() - now
print "Total time", total