MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / _test_dbapi_raw

Function _test_dbapi_raw

examples/performance/single_inserts.py:139–178  ·  view source on GitHub ↗
(n, connect)

Source from the content-addressed store, hash-verified

137
138
139def _test_dbapi_raw(n, connect):
140 compiled = (
141 Customer.__table__.insert()
142 .values(name=bindparam("name"), description=bindparam("description"))
143 .compile(dialect=engine.dialect)
144 )
145
146 if compiled.positional:
147 args = (
148 ("customer name %d" % i, "customer description %d" % i)
149 for i in range(n)
150 )
151 else:
152 args = (
153 dict(
154 name="customer name %d" % i,
155 description="customer description %d" % i,
156 )
157 for i in range(n)
158 )
159 sql = str(compiled)
160
161 if connect:
162 for arg in args:
163 # there's no connection pool, so if these were distinct
164 # calls, we'd be connecting each time
165 conn = engine.pool._creator()
166 cursor = conn.cursor()
167 cursor.execute(sql, arg)
168 cursor.lastrowid
169 conn.commit()
170 conn.close()
171 else:
172 for arg in args:
173 conn = engine.raw_connection()
174 cursor = conn.cursor()
175 cursor.execute(sql, arg)
176 cursor.lastrowid
177 conn.commit()
178 conn.close()
179
180
181if __name__ == "__main__":

Callers 2

test_dbapi_raw_w_connectFunction · 0.70
test_dbapi_raw_w_poolFunction · 0.70

Calls 10

bindparamFunction · 0.90
compileMethod · 0.45
valuesMethod · 0.45
insertMethod · 0.45
_creatorMethod · 0.45
cursorMethod · 0.45
executeMethod · 0.45
commitMethod · 0.45
closeMethod · 0.45
raw_connectionMethod · 0.45

Tested by 2

test_dbapi_raw_w_connectFunction · 0.56
test_dbapi_raw_w_poolFunction · 0.56