Peter van Dijk wrote:
every time you open an sqlite database file, the sqlite library has to parse all table structures. It is much better to keep your connection/handle open for longer periods of time.

On my XP box it takes about 220us to connect to an SQLite database from Python, whether there is 1 table or 1000.

A "connect" here is "C=sqlite3.Connection('tmp.db'); C.close()"

   0.121: To create 1 tables with 1000 rows each
   0.223: To connect 1000 times (222us per connect)

   0.651: To create 10 tables with 1000 rows each
   0.236: To connect 1000 times (234us per connect)

   5.776: To create 100 tables with 1000 rows each
   0.224: To connect 1000 times (223us per connect)

  58.393: To create 1000 tables with 1000 rows each
   0.219: To connect 1000 times (218us per connect)

I guess the parsing is delayed until necessary because what takes the time is, say, the first select:

A "connect" here is "C=sqlite3.Connection('tmp.db'); C.execute('select a from t0 limit 1'); C.close()"

   0.119: To create 1 tables with 1000 rows each
   1.008: To connect 1000 times (1007us per connect)

   0.638: To create 10 tables with 1000 rows each
   1.264: To connect 1000 times (1263us per connect)

   5.801: To create 100 tables with 1000 rows each
   4.193: To connect 1000 times (4192us per connect)

  58.419: To create 1000 tables with 1000 rows each
  32.468: To connect 1000 times (32466us per connect)

So the difference in connect times between a database with 1 table and 10 tables is about 25%, fairly trivial 250us. With 100 tables connect time is 3ms, worse by a factor of 4 but still not bad. With 1000 tables the 33ms connect time becomes significant, but I would imagine that 1000 table databases must be pretty unusual.

Martin

-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------

Reply via email to