Created
January 10, 2014 04:13
-
-
Save zzzeek/8346896 to your computer and use it in GitHub Desktop.
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 | |
engine = create_engine('mysql://scott:tiger@localhost/test') | |
engine.execute("DROP TABLE IF EXISTS test_stuff") | |
engine.execute("CREATE TABLE test_stuff (data varchar(30))") | |
engine.execute("INSERT INTO test_stuff (data) values (%s)", | |
[("d%d" % i,) for i in xrange(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() | |
connection = engine.raw_connection() | |
@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() | |
$ python test.py | |
Profile report for target 'anonymous_target' | |
Thu Jan 9 23:13:33 2014 go.prof | |
82 function calls in 0.055 seconds | |
Ordered by: internal time, call count | |
ncalls tottime percall cumtime percall filename:lineno(function) | |
1 0.022 0.022 0.022 0.022 /Users/classic/dev/sqlalchemy/lib/sqlalchemy/engine/result.py:747(process_rows) | |
1 0.009 0.009 0.009 0.009 {built-in method fetch_row} | |
1 0.009 0.009 0.053 0.053 test.py:15(go) | |
1 0.007 0.007 0.007 0.007 {method 'query' of '_mysql.connection' objects} | |
1 0.004 0.004 0.004 0.004 {method 'store_result' of '_mysql.connection' objects} | |
1 0.002 0.002 0.055 0.055 <string>:1(<module>) | |
1 0.000 0.000 0.000 0.000 /Users/classic/dev/sqlalchemy/lib/sqlalchemy/engine/result.py:174(__init__) | |
1 0.000 0.000 0.009 0.009 build/bdist.macosx-10.4-x86_64/egg/MySQLdb/cursors.py:320(_post_get_result) | |
1 0.000 0.000 0.004 0.004 build/bdist.macosx-10.4-x86_64/egg/MySQLdb/cursors.py:117(_do_get_result) | |
1 0.000 0.000 0.000 0.000 /Users/classic/dev/sqlalchemy/lib/sqlalchemy/engine/default.py:552(_init_statement) | |
1 0.000 0.000 0.000 0.000 build/bdist.macosx-10.4-x86_64/egg/MySQLdb/cursors.py:82(_warning_check) | |
1 0.000 0.000 0.021 0.021 /Users/classic/dev/sqlalchemy/lib/sqlalchemy/engine/base.py:812(_execute_context) | |
1 0.000 0.000 0.021 0.021 build/bdist.macosx-10.4-x86_64/egg/MySQLdb/cursors.py:139(execute) | |
1 0.000 0.000 0.000 0.000 build/bdist.macosx-10.4-x86_64/egg/MySQLdb/cursors.py:50(__init__) | |
1 0.000 0.000 0.000 0.000 build/bdist.macosx-10.4-x86_64/egg/MySQLdb/cursors.py:97(nextset) | |
2 0.000 0.000 0.000 0.000 build/bdist.macosx-10.4-x86_64/egg/MySQLdb/cursors.py:342(fetchall) | |
1 0.000 0.000 0.023 0.023 /Users/classic/dev/sqlalchemy/lib/sqlalchemy/engine/result.py:763(fetchall) | |
1 0.000 0.000 0.011 0.011 build/bdist.macosx-10.4-x86_64/egg/MySQLdb/cursors.py:277(_do_query) | |
1 0.000 0.000 0.021 0.021 /Users/classic/dev/sqlalchemy/lib/sqlalchemy/engine/base.py:790(_execute_text) | |
1 0.000 0.000 0.000 0.000 /Users/classic/dev/sqlalchemy/lib/sqlalchemy/engine/default.py:618(should_autocommit) | |
1 0.000 0.000 0.000 0.000 /Users/classic/dev/sqlalchemy/lib/sqlalchemy/engine/result.py:504(close) | |
1 0.000 0.000 0.009 0.009 build/bdist.macosx-10.4-x86_64/egg/MySQLdb/cursors.py:286(_fetch_row) | |
1 0.000 0.000 0.000 0.000 {method 'match' of '_sre.SRE_Pattern' objects} | |
1 0.000 0.000 0.021 0.021 /Users/classic/dev/sqlalchemy/lib/sqlalchemy/engine/base.py:596(execute) | |
1 0.000 0.000 0.000 0.000 build/bdist.macosx-10.4-x86_64/egg/MySQLdb/cursors.py:67(__del__) | |
2 0.000 0.000 0.000 0.000 /Users/classic/dev/sqlalchemy/lib/sqlalchemy/util/langhelpers.py:686(__get__) | |
1 0.000 0.000 0.000 0.000 /Users/classic/dev/sqlalchemy/lib/sqlalchemy/sql/type_api.py:301(_cached_result_processor) | |
1 0.000 0.000 0.000 0.000 /Users/classic/dev/sqlalchemy/lib/sqlalchemy/engine/base.py:955(_safe_close_cursor) | |
1 0.000 0.000 0.000 0.000 /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/weakref.py:255(__getitem__) | |
1 0.000 0.000 0.000 0.000 /Users/classic/dev/sqlalchemy/lib/sqlalchemy/engine/result.py:381(__init__) | |
1 0.000 0.000 0.004 0.004 build/bdist.macosx-10.4-x86_64/egg/MySQLdb/cursors.py:313(_get_result) | |
1 0.000 0.000 0.000 0.000 /Users/classic/dev/sqlalchemy/lib/sqlalchemy/engine/default.py:720(get_result_proxy) | |
3 0.000 0.000 0.000 0.000 {isinstance} | |
2 0.000 0.000 0.000 0.000 build/bdist.macosx-10.4-x86_64/egg/MySQLdb/cursors.py:72(close) | |
1 0.000 0.000 0.000 0.000 /Users/classic/dev/sqlalchemy/lib/sqlalchemy/engine/default.py:610(no_parameters) | |
1 0.000 0.000 0.021 0.021 build/bdist.macosx-10.4-x86_64/egg/MySQLdb/cursors.py:315(_query) | |
1 0.000 0.000 0.000 0.000 {method 'next_result' of '_mysql.connection' objects} | |
1 0.000 0.000 0.000 0.000 /Users/classic/dev/sqlalchemy/lib/sqlalchemy/engine/result.py:391(_init_metadata) | |
1 0.000 0.000 0.000 0.000 {method 'escape' of '_mysql.connection' objects} | |
3 0.000 0.000 0.000 0.000 {len} | |
1 0.000 0.000 0.000 0.000 {method 'update' of 'dict' objects} | |
1 0.000 0.000 0.000 0.000 /Users/classic/dev/sqlalchemy/lib/sqlalchemy/engine/default.py:679(get_result_processor) | |
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 /Users/classic/dev/sqlalchemy/lib/sqlalchemy/pool.py:547(cursor) | |
1 0.000 0.000 0.000 0.000 /Users/classic/dev/sqlalchemy/lib/sqlalchemy/engine/default.py:670(create_cursor) | |
1 0.000 0.000 0.000 0.000 build/bdist.macosx-10.4-x86_64/egg/MySQLdb/connections.py:234(cursor) | |
1 0.000 0.000 0.000 0.000 /Users/classic/dev/sqlalchemy/lib/sqlalchemy/dialects/mysql/base.py:1356(should_autocommit_text) | |
1 0.000 0.000 0.000 0.000 build/bdist.macosx-10.4-x86_64/egg/MySQLdb/connections.py:253(literal) | |
5 0.000 0.000 0.000 0.000 build/bdist.macosx-10.4-x86_64/egg/MySQLdb/cursors.py:134(_get_db) | |
2 0.000 0.000 0.000 0.000 {method 'append' of 'list' objects} | |
1 0.000 0.000 0.021 0.021 /Users/classic/dev/sqlalchemy/lib/sqlalchemy/engine/default.py:387(do_execute) | |
1 0.000 0.000 0.000 0.000 /Users/classic/dev/sqlalchemy/lib/sqlalchemy/engine/result.py:732(_fetchall_impl) | |
1 0.000 0.000 0.000 0.000 /Users/classic/dev/sqlalchemy/lib/sqlalchemy/engine/result.py:499(_cursor_description) | |
1 0.000 0.000 0.000 0.000 {method 'affected_rows' of '_mysql.connection' objects} | |
1 0.000 0.000 0.000 0.000 {method 'character_set_name' of '_mysql.connection' objects} | |
1 0.000 0.000 0.000 0.000 {built-in method describe} | |
3 0.000 0.000 0.000 0.000 {method 'get' of 'dict' objects} | |
2 0.000 0.000 0.000 0.000 build/bdist.macosx-10.4-x86_64/egg/MySQLdb/cursors.py:78(_check_executed) | |
1 0.000 0.000 0.000 0.000 {_weakref.proxy} | |
1 0.000 0.000 0.000 0.000 {sqlalchemy.cutils._distill_params} | |
1 0.000 0.000 0.000 0.000 {method 'info' of '_mysql.connection' objects} | |
1 0.000 0.000 0.000 0.000 {method 'insert_id' of '_mysql.connection' objects} | |
1 0.000 0.000 0.000 0.000 {built-in method __new__ of type object at 0x1001534e8} | |
1 0.000 0.000 0.000 0.000 {method 'warning_count' of '_mysql.connection' objects} | |
1 0.000 0.000 0.000 0.000 {built-in method field_flags} | |
1 0.000 0.000 0.000 0.000 {method 'setdefault' of 'dict' objects} | |
1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects} | |
Profile report for target 'anonymous_target' | |
Thu Jan 9 23:13:33 2014 go.prof | |
44 function calls in 0.032 seconds | |
Ordered by: internal time, call count | |
ncalls tottime percall cumtime percall filename:lineno(function) | |
1 0.010 0.010 0.010 0.010 {method 'query' of '_mysql.connection' objects} | |
1 0.009 0.009 0.009 0.009 {built-in method fetch_row} | |
1 0.006 0.006 0.030 0.030 test.py:24(go) | |
1 0.005 0.005 0.005 0.005 {method 'store_result' of '_mysql.connection' objects} | |
1 0.001 0.001 0.032 0.032 <string>:1(<module>) | |
1 0.000 0.000 0.005 0.005 build/bdist.macosx-10.4-x86_64/egg/MySQLdb/cursors.py:117(_do_get_result) | |
1 0.000 0.000 0.009 0.009 build/bdist.macosx-10.4-x86_64/egg/MySQLdb/cursors.py:320(_post_get_result) | |
1 0.000 0.000 0.015 0.015 build/bdist.macosx-10.4-x86_64/egg/MySQLdb/cursors.py:277(_do_query) | |
1 0.000 0.000 0.005 0.005 build/bdist.macosx-10.4-x86_64/egg/MySQLdb/cursors.py:313(_get_result) | |
1 0.000 0.000 0.000 0.000 build/bdist.macosx-10.4-x86_64/egg/MySQLdb/cursors.py:82(_warning_check) | |
1 0.000 0.000 0.000 0.000 build/bdist.macosx-10.4-x86_64/egg/MySQLdb/cursors.py:50(__init__) | |
2 0.000 0.000 0.000 0.000 build/bdist.macosx-10.4-x86_64/egg/MySQLdb/cursors.py:342(fetchall) | |
1 0.000 0.000 0.024 0.024 build/bdist.macosx-10.4-x86_64/egg/MySQLdb/cursors.py:139(execute) | |
1 0.000 0.000 0.000 0.000 build/bdist.macosx-10.4-x86_64/egg/MySQLdb/cursors.py:97(nextset) | |
5 0.000 0.000 0.000 0.000 build/bdist.macosx-10.4-x86_64/egg/MySQLdb/cursors.py:134(_get_db) | |
2 0.000 0.000 0.000 0.000 build/bdist.macosx-10.4-x86_64/egg/MySQLdb/cursors.py:72(close) | |
1 0.000 0.000 0.024 0.024 build/bdist.macosx-10.4-x86_64/egg/MySQLdb/cursors.py:315(_query) | |
1 0.000 0.000 0.009 0.009 build/bdist.macosx-10.4-x86_64/egg/MySQLdb/cursors.py:286(_fetch_row) | |
2 0.000 0.000 0.000 0.000 test.py:28(<genexpr>) | |
1 0.000 0.000 0.000 0.000 /Users/classic/dev/sqlalchemy/lib/sqlalchemy/pool.py:547(cursor) | |
1 0.000 0.000 0.000 0.000 {method 'next_result' of '_mysql.connection' objects} | |
1 0.000 0.000 0.000 0.000 {built-in method describe} | |
1 0.000 0.000 0.000 0.000 {method 'affected_rows' of '_mysql.connection' objects} | |
1 0.000 0.000 0.000 0.000 {isinstance} | |
1 0.000 0.000 0.000 0.000 build/bdist.macosx-10.4-x86_64/egg/MySQLdb/connections.py:234(cursor) | |
1 0.000 0.000 0.000 0.000 build/bdist.macosx-10.4-x86_64/egg/MySQLdb/cursors.py:67(__del__) | |
2 0.000 0.000 0.000 0.000 {len} | |
2 0.000 0.000 0.000 0.000 build/bdist.macosx-10.4-x86_64/egg/MySQLdb/cursors.py:78(_check_executed) | |
1 0.000 0.000 0.000 0.000 {_weakref.proxy} | |
1 0.000 0.000 0.000 0.000 {method 'info' of '_mysql.connection' objects} | |
1 0.000 0.000 0.000 0.000 {method 'insert_id' of '_mysql.connection' objects} | |
1 0.000 0.000 0.000 0.000 {method 'warning_count' of '_mysql.connection' objects} | |
1 0.000 0.000 0.000 0.000 {method 'character_set_name' of '_mysql.connection' objects} | |
1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects} | |
1 0.000 0.000 0.000 0.000 {built-in method field_flags} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment