Message224707
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. |
|
Date |
User |
Action |
Args |
2014-08-04 10:37:41 | serhiy.storchaka | set | recipients:
+ serhiy.storchaka, rhettinger, ghaering, ncoghlan, eric.araujo, BreamoreBoy, petri.lehtinen, dlenski, Russell.Sim |
2014-08-04 10:37:41 | serhiy.storchaka | set | messageid: <1407148661.42.0.358356273878.issue13299@psf.upfronthosting.co.za> |
2014-08-04 10:37:41 | serhiy.storchaka | link | issue13299 messages |
2014-08-04 10:37:41 | serhiy.storchaka | create | |
|