天天看點

SQLite.NET提供程式的選擇

今日用到了SQLite,發現這個資料庫進行了很大的更新,從3.4.X更新到3.5.X了。版本号發生改變,API接口OS層發生重大改變。

SQLite version 3.5.0 introduces a new OS interface layer that is incompatible with all prior versions of SQLite. In addition, a few existing interfaces have been generalized to work across all database connections within a process rather than just all connections within a thread. The purpose of this article is to describe the changes to 3.5.0 in detail so that users of prior versions of SQLite can judge what, if any, effort will be required to upgrade to newer versions.

A quick enumeration of the changes in SQLite version 3.5.0 is provide here. Subsequent sections will describe these changes in more detail.

The OS interface layer has been completely reworked:

The undocumented <b>sqlite3_os_switch()</b> interface has been removed.

The <b>SQLITE_ENABLE_REDEF_IO</b> compile-time flag no longer functions. I/O procedures are now always redefinable.

The optional shared cache and memory management features that were introduced in version 3.3.0 can now be used across multiple threads within the same process. Formerly, these extensions only applied to database connections operating within a single thread.

Restrictions on the use of the same database connection by multiple threads have been dropped. It is now safe for multiple threads to use the same database connection at the same time.

There is now a compile-time option that allows an application to define alternative malloc()/free() implementations without having to modify any core SQLite code.

There is now a compile-time option that allows an application to define alternative mutex implementations without having to modify any core SQLite code.

Of these changes, only 1a and 2a through 2c are incompatibilities in any formal sense. But users who have previously made custom modifications to the SQLite source (for example to add a custom OS layer for embedded hardware) might find that these changes have a larger impact. On the other hand, an important goal of these changes is to make it much easier to customize SQLite for use on different operating systems.

由于存儲層的改變,SQLite.NET的各個版本也發生了變化:

SQLite.NET的新版本主要是随SQLite3.4-&gt;3.5的改進而進行了相應的修改。性能有很大變化,對比如下:

1.0.46 test

Beginning Test on System.Data.SQLite.SQLiteConnection

SUCCESS - CreateTable

SUCCESS - Full Text Search

SUCCESS - DataType Test

SUCCESS - Dispose pattern test

SUCCESS - KeyInfo Fetch

SUCCESS - Transaction Enlistment

SUCCESS - Guid Test

SUCCESS - InsertTable

SUCCESS - VerifyInsert

SUCCESS - CoersionTest

SUCCESS - ParameterizedInsert

SUCCESS - BinaryInsert (using named parameter)

SUCCESS - VerifyBinaryData

SUCCESS - LockTest

SUCCESS - ParameterizedInsertMissingParams

          Inserting using CommandBuilder and DataAdapter

          -&gt; (10,000 rows) ...

          -&gt; Insert Ends in 210 ms ... Commits in 481 ms

          -&gt;(with identity fetch) (10,000 rows) ...

          -&gt; Insert Ends in 300 ms ... Commits in 201 ms

          Fast insert using parameters and prepared statement

          -&gt; (100,000 rows) Begins ...

          -&gt; Ends in 801 ms ... Commits in 441 ms

          User Function iteration of 120003 records in 240 ms

          Raw iteration of 120003 records in 100 ms

          Intrinsic Function iteration of 120003 records in 70 ms

          User (text)  command executed 397517 times in 1 second.

          UserFunction command executed 570342 times in 1 second.

          Intrinsic    command executed 932032 times in 1 second.

          Intrin (txt) command executed 747247 times in 1 second.

          Raw Value    command executed 1013199 times in 1 second.

          UserAggregate executed 17 times in 1 second.

SUCCESS - UserCollation

SUCCESS - DropTable

Tests Finished.

1.0.48 test

          -&gt; Insert Ends in 411 ms ... Commits in 100 ms

          -&gt; Insert Ends in 440 ms ... Commits in 131 ms

          -&gt; Ends in 1312 ms ... Commits in 340 ms

          User Function iteration of 120003 records in 191 ms

          Raw iteration of 120003 records in 130 ms

          Intrinsic Function iteration of 120003 records in 140 ms

          User (text)  command executed 298951 times in 1 second.

          UserFunction command executed 418648 times in 1 second.

          Intrinsic    command executed 599105 times in 1 second.

          Intrin (txt) command executed 458549 times in 1 second.

          Raw Value    command executed 655652 times in 1 second.

          UserAggregate executed 15 times in 1 second.

由測試可知,3.4版的SQLite在很多方面,性能依然要比3.5版的SQLite強不少。但是SQLite 3.5版在OS适配層的改進(引入VFS對象),提高了資料的寫入效率,明顯的,其Commits的時間總是較少。

結論:

3.4版的SQLite在資料插入較多的應用情況下,效率仍然較好;

3.5版的SQLite在資料寫入磁盤方面有很大改進,但其顯然在記憶體資料組織方面還有待改進,插入操作所耗費的時間明顯比3.4版要長;

感覺3.4版的SQLite是非常穩定的一個版本。3.5版,看來等等再使用了。

本文轉自斯克迪亞部落格園部落格,原文連結:http://www.cnblogs.com/sgsoft/archive/2008/02/19/1074055.html,如需轉載請自行聯系原作者