MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / runit_persist

Function runit_persist

test/perf/orm2010.py:64–98  ·  view source on GitHub ↗
(status, factor=1, query_runs=5)

Source from the content-addressed store, hash-verified

62
63
64def runit_persist(status, factor=1, query_runs=5):
65 num_bosses = 100 * factor
66 num_grunts = num_bosses * 100
67
68 bosses = [
69 Boss(name="Boss %d" % i, golf_average=Decimal(random.randint(40, 150)))
70 for i in range(num_bosses)
71 ]
72
73 sess.add_all(bosses)
74 status("Added %d boss objects" % num_bosses)
75
76 grunts = [
77 Grunt(
78 name="Grunt %d" % i,
79 savings=Decimal(random.randint(5000000, 15000000) / 100),
80 )
81 for i in range(num_grunts)
82 ]
83 status("Added %d grunt objects" % num_grunts)
84
85 while grunts:
86 # this doesn't associate grunts with bosses evenly,
87 # just associates lots of them with a relatively small
88 # handful of bosses
89 batch_size = 100
90 batch_num = (num_grunts - len(grunts)) / batch_size
91 boss = sess.query(Boss).filter_by(name="Boss %d" % batch_num).first()
92 for grunt in grunts[0:batch_size]:
93 grunt.employer = boss
94
95 grunts = grunts[batch_size:]
96
97 sess.commit()
98 status("Associated grunts w/ bosses and committed")
99
100
101def runit_query_runs(status, factor=1, query_runs=5):

Callers 1

run_with_timeFunction · 0.85

Calls 8

statusFunction · 0.85
GruntClass · 0.85
BossClass · 0.70
add_allMethod · 0.45
firstMethod · 0.45
filter_byMethod · 0.45
queryMethod · 0.45
commitMethod · 0.45

Tested by

no test coverage detected