Last active
October 12, 2022 02:27
-
-
Save zzzeek/8479592 to your computer and use it in GitHub Desktop.
cx_oracle vs. SQLAlchemy core, revised
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sqlalchemy.testing.profiling import profiled | |
from sqlalchemy import create_engine | |
from sqlalchemy import event | |
engine = create_engine('oracle://scott:tiger@localhost/xe') | |
# disregard all output type handling - Python unicodes | |
# will no longer be supported | |
@event.listens_for(engine, "connect") | |
def connect(dbapi_connection, connection_record): | |
dbapi_connection.outputtypehandler = None | |
try: | |
engine.execute("DROP TABLE test_stuff") | |
except: | |
pass | |
engine.execute("CREATE TABLE test_stuff (data varchar(30))") | |
engine.execute("INSERT INTO test_stuff (data) values (:data)", | |
[{"data": "d%d" % i} for i in range(50000)]) | |
with engine.connect() as conn: | |
@profiled() | |
def go(): | |
rows = conn.execute("select * from test_stuff") | |
data = [row['data'] for row in rows.fetchall()] | |
go() | |
engine = create_engine('oracle://scott:tiger@localhost/xe') | |
connection = engine.pool._creator() | |
@profiled() | |
def go(): | |
cursor = connection.cursor() | |
cursor.execute("select * from test_stuff") | |
row_idx = dict((desc[0], i) for i, desc in enumerate(cursor.description)) | |
data = [row[row_idx['DATA']] for row in cursor.fetchall()] | |
cursor.close() | |
go() | |
[classic@f1 sqlalchemy]$ python test.py | |
Profile report for target 'anonymous_target' | |
Fri Jan 17 14:24:08 2014 go.prof | |
56 function calls in 0.113 CPU seconds | |
Ordered by: internal time, call count | |
ncalls tottime percall cumtime percall filename:lineno(function) | |
1 0.074 0.074 0.074 0.074 {method 'fetchall' of 'OracleCursor' objects} | |
1 0.019 0.019 0.019 0.019 /mnt/hgfs/classic/dev/sqlalchemy/lib/sqlalchemy/engine/result.py:747(process_rows) | |
1 0.013 0.013 0.112 0.112 test.py:25(go) | |
1 0.006 0.006 0.006 0.006 {method 'execute' of 'OracleCursor' objects} | |
1 0.001 0.001 0.113 0.113 <string>:1(<module>) | |
1 0.000 0.000 0.093 0.093 /mnt/hgfs/classic/dev/sqlalchemy/lib/sqlalchemy/engine/result.py:763(fetchall) | |
1 0.000 0.000 0.000 0.000 {method 'close' of 'OracleCursor' objects} | |
1 0.000 0.000 0.000 0.000 /mnt/hgfs/classic/dev/sqlalchemy/lib/sqlalchemy/engine/result.py:174(__init__) | |
1 0.000 0.000 0.000 0.000 /mnt/hgfs/classic/dev/sqlalchemy/lib/sqlalchemy/dialects/oracle/cx_oracle.py:452(get_result_proxy) | |
1 0.000 0.000 0.006 0.006 /mnt/hgfs/classic/dev/sqlalchemy/lib/sqlalchemy/engine/base.py:856(_execute_context) | |
1 0.000 0.000 0.000 0.000 /mnt/hgfs/classic/dev/sqlalchemy/lib/sqlalchemy/engine/default.py:561(_init_statement) | |
1 0.000 0.000 0.000 0.000 /mnt/hgfs/classic/dev/sqlalchemy/lib/sqlalchemy/engine/default.py:627(should_autocommit) | |
1 0.000 0.000 0.000 0.000 /mnt/hgfs/classic/dev/sqlalchemy/lib/sqlalchemy/engine/base.py:999(_safe_close_cursor) | |
1 0.000 0.000 0.000 0.000 /mnt/hgfs/classic/dev/sqlalchemy/lib/sqlalchemy/engine/result.py:504(close) | |
1 0.000 0.000 0.000 0.000 /mnt/hgfs/classic/dev/sqlalchemy/lib/sqlalchemy/dialects/oracle/base.py:814(normalize_name) | |
2 0.000 0.000 0.000 0.000 {built-in method match} | |
1 0.000 0.000 0.000 0.000 /mnt/hgfs/classic/dev/sqlalchemy/lib/sqlalchemy/sql/compiler.py:2765(_requires_quotes) | |
2 0.000 0.000 0.000 0.000 {hasattr} | |
1 0.000 0.000 0.000 0.000 /mnt/hgfs/classic/dev/sqlalchemy/lib/sqlalchemy/engine/result.py:381(__init__) | |
2 0.000 0.000 0.000 0.000 /mnt/hgfs/classic/dev/sqlalchemy/lib/sqlalchemy/util/langhelpers.py:686(__get__) | |
1 0.000 0.000 0.006 0.006 /mnt/hgfs/classic/dev/sqlalchemy/lib/sqlalchemy/engine/base.py:640(execute) | |
1 0.000 0.000 0.074 0.074 /mnt/hgfs/classic/dev/sqlalchemy/lib/sqlalchemy/engine/result.py:732(_fetchall_impl) | |
1 0.000 0.000 0.000 0.000 /mnt/hgfs/classic/dev/sqlalchemy/lib/sqlalchemy/sql/type_api.py:301(_cached_result_processor) | |
1 0.000 0.000 0.006 0.006 /mnt/hgfs/classic/dev/sqlalchemy/lib/sqlalchemy/engine/base.py:834(_execute_text) | |
1 0.000 0.000 0.000 0.000 /mnt/hgfs/classic/dev/sqlalchemy/lib/sqlalchemy/dialects/oracle/cx_oracle.py:445(create_cursor) | |
1 0.000 0.000 0.006 0.006 /mnt/hgfs/classic/dev/sqlalchemy/lib/sqlalchemy/engine/default.py:396(do_execute) | |
3 0.000 0.000 0.000 0.000 {isinstance} | |
1 0.000 0.000 0.000 0.000 /mnt/hgfs/classic/dev/sqlalchemy/lib/sqlalchemy/engine/result.py:499(_cursor_description) | |
1 0.000 0.000 0.000 0.000 /mnt/hgfs/classic/dev/sqlalchemy/lib/sqlalchemy/engine/result.py:391(_init_metadata) | |
1 0.000 0.000 0.000 0.000 /mnt/hgfs/classic/dev/sqlalchemy/lib/sqlalchemy/pool.py:673(cursor) | |
3 0.000 0.000 0.000 0.000 {method 'get' of 'dict' objects} | |
1 0.000 0.000 0.000 0.000 {method 'process' of 'sqlalchemy.cprocessors.UnicodeResultProcessor' objects} | |
1 0.000 0.000 0.000 0.000 /mnt/hgfs/classic/dev/sqlalchemy/lib/sqlalchemy/engine/default.py:619(no_parameters) | |
1 0.000 0.000 0.000 0.000 /mnt/hgfs/classic/dev/sqlalchemy/lib/sqlalchemy/engine/default.py:688(get_result_processor) | |
1 0.000 0.000 0.000 0.000 /usr/lib/python2.7/weakref.py:255(__getitem__) | |
3 0.000 0.000 0.000 0.000 {method 'lower' of 'unicode' objects} | |
1 0.000 0.000 0.000 0.000 {method 'cursor' of 'cx_Oracle.Connection' objects} | |
1 0.000 0.000 0.000 0.000 {method 'update' of 'dict' objects} | |
1 0.000 0.000 0.000 0.000 {method 'upper' of 'unicode' objects} | |
1 0.000 0.000 0.000 0.000 /mnt/hgfs/classic/dev/sqlalchemy/lib/sqlalchemy/engine/default.py:676(should_autocommit_text) | |
2 0.000 0.000 0.000 0.000 {method 'append' of 'list' objects} | |
1 0.000 0.000 0.000 0.000 {len} | |
1 0.000 0.000 0.000 0.000 {sqlalchemy.cutils._distill_params} | |
1 0.000 0.000 0.000 0.000 {method 'setdefault' of 'dict' objects} | |
1 0.000 0.000 0.000 0.000 {built-in method __new__ of type object at 0x5eb6b60} | |
1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects} | |
Profile report for target 'anonymous_target' | |
Fri Jan 17 14:24:08 2014 go.prof | |
9 function calls in 0.086 CPU seconds | |
Ordered by: internal time, call count | |
ncalls tottime percall cumtime percall filename:lineno(function) | |
1 0.076 0.076 0.076 0.076 {method 'fetchall' of 'OracleCursor' objects} | |
1 0.009 0.009 0.085 0.085 test.py:35(go) | |
1 0.001 0.001 0.086 0.086 <string>:1(<module>) | |
1 0.000 0.000 0.000 0.000 {method 'execute' of 'OracleCursor' objects} | |
1 0.000 0.000 0.000 0.000 {method 'close' of 'OracleCursor' objects} | |
1 0.000 0.000 0.000 0.000 {method 'cursor' of 'cx_Oracle.Connection' objects} | |
2 0.000 0.000 0.000 0.000 test.py:39(<genexpr>) | |
1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment