Serhiy Storchaka added the comment:
Yes, above microbenchmarks measure the time of execute() + the time of fetching
one row. Here is more precise microbenchmarks.
$ ./python -m timeit -s "import sqlite3; con = sqlite3.connect(':memory:');
con.execute('create table t (a, b)')" -s "for i in range(100):
con.execute('insert into t values (1, 2)')" -- "con.execute('select * from
t').fetchall()"
1000 loops, best of 3: 624 usec per loop
$ ./python -m timeit -s "import sqlite3; con = sqlite3.connect(':memory:');
con.row_factory = sqlite3.Row; con.execute('create table t (a, b)')" -s "for i
in range(100): con.execute('insert into t values (1, 2)')" --
"con.execute('select * from t').fetchall()"
1000 loops, best of 3: 915 usec per loop
$ ./python -m timeit -s "import sqlite3; con = sqlite3.connect(':memory:');
con.row_factory = sqlite3.NamedTupleRow; con.execute('create table t (a, b)')"
-s "for i in range(100): con.execute('insert into t values (1, 2)')" --
"con.execute('select * from t').fetchall()"
100 loops, best of 3: 6.21 msec per loop
Here sqlite3.Row is about 1.5 times slower than tuple, but
sqlite3.NamedTupleRow is about 7 times slower than sqlite3.Row.
With C implementation of lru_cache() (issue14373) the result is much better:
100 loops, best of 3: 3.16 msec per loop
And it will be even more faster (up to 1.7x) when add to the Cursor class a
method which returns a tuple of field names.
----------
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue13299>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com