├── .gitignore ├── README.md ├── References └── LiteDBv3.dll ├── TestPerfLiteDB.sln └── TestPerfLiteDB ├── App.config ├── Engines ├── ITest.cs ├── LiteDB_Test.cs └── SQLite_Test.cs ├── Program.cs ├── Properties └── AssemblyInfo.cs ├── TestPerfLiteDB.csproj ├── Utils └── Helper.cs └── packages.config /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | x64/ 19 | x86/ 20 | bld/ 21 | [Bb]in/ 22 | [Oo]bj/ 23 | [Ll]og/ 24 | 25 | # Visual Studio 2015 cache/options directory 26 | .vs/ 27 | # Uncomment if you have tasks that create the project's static files in wwwroot 28 | #wwwroot/ 29 | 30 | # MSTest test Results 31 | [Tt]est[Rr]esult*/ 32 | [Bb]uild[Ll]og.* 33 | 34 | # NUNIT 35 | *.VisualState.xml 36 | TestResult.xml 37 | 38 | # Build Results of an ATL Project 39 | [Dd]ebugPS/ 40 | [Rr]eleasePS/ 41 | dlldata.c 42 | 43 | # DNX 44 | project.lock.json 45 | artifacts/ 46 | 47 | *_i.c 48 | *_p.c 49 | *_i.h 50 | *.ilk 51 | *.meta 52 | *.obj 53 | *.pch 54 | *.pdb 55 | *.pgc 56 | *.pgd 57 | *.rsp 58 | *.sbr 59 | *.tlb 60 | *.tli 61 | *.tlh 62 | *.tmp 63 | *.tmp_proj 64 | *.log 65 | *.vspscc 66 | *.vssscc 67 | .builds 68 | *.pidb 69 | *.svclog 70 | *.scc 71 | 72 | # Chutzpah Test files 73 | _Chutzpah* 74 | 75 | # Visual C++ cache files 76 | ipch/ 77 | *.aps 78 | *.ncb 79 | *.opendb 80 | *.opensdf 81 | *.sdf 82 | *.cachefile 83 | *.VC.db 84 | *.VC.VC.opendb 85 | 86 | # Visual Studio profiler 87 | *.psess 88 | *.vsp 89 | *.vspx 90 | *.sap 91 | 92 | # TFS 2012 Local Workspace 93 | $tf/ 94 | 95 | # Guidance Automation Toolkit 96 | *.gpState 97 | 98 | # ReSharper is a .NET coding add-in 99 | _ReSharper*/ 100 | *.[Rr]e[Ss]harper 101 | *.DotSettings.user 102 | 103 | # JustCode is a .NET coding add-in 104 | .JustCode 105 | 106 | # TeamCity is a build add-in 107 | _TeamCity* 108 | 109 | # DotCover is a Code Coverage Tool 110 | *.dotCover 111 | 112 | # NCrunch 113 | _NCrunch_* 114 | .*crunch*.local.xml 115 | nCrunchTemp_* 116 | 117 | # MightyMoose 118 | *.mm.* 119 | AutoTest.Net/ 120 | 121 | # Web workbench (sass) 122 | .sass-cache/ 123 | 124 | # Installshield output folder 125 | [Ee]xpress/ 126 | 127 | # DocProject is a documentation generator add-in 128 | DocProject/buildhelp/ 129 | DocProject/Help/*.HxT 130 | DocProject/Help/*.HxC 131 | DocProject/Help/*.hhc 132 | DocProject/Help/*.hhk 133 | DocProject/Help/*.hhp 134 | DocProject/Help/Html2 135 | DocProject/Help/html 136 | 137 | # Click-Once directory 138 | publish/ 139 | 140 | # Publish Web Output 141 | *.[Pp]ublish.xml 142 | *.azurePubxml 143 | # TODO: Comment the next line if you want to checkin your web deploy settings 144 | # but database connection strings (with potential passwords) will be unencrypted 145 | *.pubxml 146 | *.publishproj 147 | 148 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 149 | # checkin your Azure Web App publish settings, but sensitive information contained 150 | # in these scripts will be unencrypted 151 | PublishScripts/ 152 | 153 | # NuGet Packages 154 | *.nupkg 155 | # The packages folder can be ignored because of Package Restore 156 | **/packages/* 157 | # except build/, which is used as an MSBuild target. 158 | !**/packages/build/ 159 | # Uncomment if necessary however generally it will be regenerated when needed 160 | #!**/packages/repositories.config 161 | # NuGet v3's project.json files produces more ignoreable files 162 | *.nuget.props 163 | *.nuget.targets 164 | 165 | # Microsoft Azure Build Output 166 | csx/ 167 | *.build.csdef 168 | 169 | # Microsoft Azure Emulator 170 | ecf/ 171 | rcf/ 172 | 173 | # Windows Store app package directories and files 174 | AppPackages/ 175 | BundleArtifacts/ 176 | Package.StoreAssociation.xml 177 | _pkginfo.txt 178 | 179 | # Visual Studio cache files 180 | # files ending in .cache can be ignored 181 | *.[Cc]ache 182 | # but keep track of directories ending in .cache 183 | !*.[Cc]ache/ 184 | 185 | # Others 186 | ClientBin/ 187 | ~$* 188 | *~ 189 | *.dbmdl 190 | *.dbproj.schemaview 191 | *.pfx 192 | *.publishsettings 193 | node_modules/ 194 | orleans.codegen.cs 195 | 196 | # Since there are multiple workflows, uncomment next line to ignore bower_components 197 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 198 | #bower_components/ 199 | 200 | # RIA/Silverlight projects 201 | Generated_Code/ 202 | 203 | # Backup & report files from converting an old project file 204 | # to a newer Visual Studio version. Backup files are not needed, 205 | # because we have git ;-) 206 | _UpgradeReport_Files/ 207 | Backup*/ 208 | UpgradeLog*.XML 209 | UpgradeLog*.htm 210 | 211 | # SQL Server files 212 | *.mdf 213 | *.ldf 214 | 215 | # Business Intelligence projects 216 | *.rdl.data 217 | *.bim.layout 218 | *.bim_*.settings 219 | 220 | # Microsoft Fakes 221 | FakesAssemblies/ 222 | 223 | # GhostDoc plugin setting file 224 | *.GhostDoc.xml 225 | 226 | # Node.js Tools for Visual Studio 227 | .ntvs_analysis.dat 228 | 229 | # Visual Studio 6 build log 230 | *.plg 231 | 232 | # Visual Studio 6 workspace options file 233 | *.opt 234 | 235 | # Visual Studio LightSwitch build output 236 | **/*.HTMLClient/GeneratedArtifacts 237 | **/*.DesktopClient/GeneratedArtifacts 238 | **/*.DesktopClient/ModelManifest.xml 239 | **/*.Server/GeneratedArtifacts 240 | **/*.Server/ModelManifest.xml 241 | _Pvt_Extensions 242 | 243 | # Paket dependency manager 244 | .paket/paket.exe 245 | paket-files/ 246 | 247 | # FAKE - F# Make 248 | .fake/ 249 | 250 | # JetBrains Rider 251 | .idea/ 252 | *.sln.iml 253 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # LiteDB-Perf 2 | 3 | A simple actions to compare SQLite and LiteDB v3 4 | 5 | Results: 6 | 7 | |5.000 records | LiteDB #1 | LiteDB #2 | LiteDB #3 | SQLite #1 | SQLite #2 | SQLite #3 | 8 | |---------------|-----------:|----------:|----------:|-----------:|----------:|----------:| 9 | |Insert | 4.999 ms | 5.690 ms | 4.839 ms | 46.379 ms | 49.296 ms | 4.107 ms | 10 | |Bulk | 236 ms | 280 ms | 219 ms | 122 ms | 122 ms | 106 ms | 11 | |Update | 3.674 ms | 3.784 ms | 3.242 ms | 47.470 ms | 48.490 ms | 4.101 ms | 12 | |CreateIndex | 176 ms | 174 ms | 176 ms | 13 ms | 36 ms | 8 ms | 13 | |Query | 204 ms | 208 ms | 93 ms | 457 ms | 463 ms | 468 ms | 14 | |Delete | 157 ms | 207 ms | 140 ms | 11 ms | 13 ms | 3 ms | 15 | |Drop | 17 ms | 56 ms | 14 ms | 11 ms | 25 ms | 3 ms | 16 | |FileLength | 7.580 kb | 7.576 kb | 7.572 kb | 3.824 kb | 3.856 kb | 3.824 kb | 17 | 18 | > Low is better 19 | 20 | LiteDB 21 | - #1 Default 22 | - #2 Encrypted 23 | - #3 Exclusive mode and no journal 24 | 25 | SQLite 26 | - #1 Default 27 | - #2 Encrypted 28 | - #3 No journal 29 | 30 | Tested on MacBook Pro 2012 i5, Win10, 8Gb RAM, SSD 31 | 32 | ``` 33 | 34 | LiteDB: default - 5000 records 35 | ============================== 36 | Insert : 4999 ms - 1000 records/second 37 | Bulk : 236 ms - 21184 records/second 38 | Update : 3674 ms - 1361 records/second 39 | CreateIndex : 176 ms - 28321 records/second 40 | Query : 204 ms - 24467 records/second 41 | Delete : 157 ms - 31722 records/second 42 | Drop : 17 ms - 289513 records/second 43 | FileLength : 7580 kb 44 | 45 | LiteDB: encrypted - 5000 records 46 | ================================ 47 | Insert : 5690 ms - 879 records/second 48 | Bulk : 280 ms - 17820 records/second 49 | Update : 3784 ms - 1321 records/second 50 | CreateIndex : 174 ms - 28669 records/second 51 | Query : 208 ms - 24037 records/second 52 | Delete : 207 ms - 24078 records/second 53 | Drop : 56 ms - 87898 records/second 54 | FileLength : 7576 kb 55 | 56 | LiteDB: exclusive no journal - 5000 records 57 | =========================================== 58 | Insert : 4839 ms - 1033 records/second 59 | Bulk : 219 ms - 22775 records/second 60 | Update : 3242 ms - 1542 records/second 61 | CreateIndex : 176 ms - 28379 records/second 62 | Query : 93 ms - 53243 records/second 63 | Delete : 140 ms - 35574 records/second 64 | Drop : 14 ms - 334283 records/second 65 | FileLength : 7572 kb 66 | 67 | SQLite: default - 5000 records 68 | ============================== 69 | Insert : 46379 ms - 108 records/second 70 | Bulk : 122 ms - 40827 records/second 71 | Update : 47470 ms - 105 records/second 72 | CreateIndex : 13 ms - 367266 records/second 73 | Query : 457 ms - 10933 records/second 74 | Delete : 11 ms - 441583 records/second 75 | Drop : 11 ms - 454141 records/second 76 | FileLength : 3824 kb 77 | 78 | SQLite: encrypted - 5000 records 79 | ================================ 80 | Insert : 49296 ms - 101 records/second 81 | Bulk : 122 ms - 40851 records/second 82 | Update : 48490 ms - 103 records/second 83 | CreateIndex : 36 ms - 136413 records/second 84 | Query : 463 ms - 10798 records/second 85 | Delete : 13 ms - 357189 records/second 86 | Drop : 25 ms - 199642 records/second 87 | FileLength : 3856 kb 88 | 89 | SQLite: no journal - 5000 records 90 | ================================= 91 | Insert : 4107 ms - 1217 records/second 92 | Bulk : 106 ms - 47121 records/second 93 | Update : 4101 ms - 1219 records/second 94 | CreateIndex : 8 ms - 592916 records/second 95 | Query : 468 ms - 10680 records/second 96 | Delete : 3 ms - 1578981 records/second 97 | Drop : 3 ms - 1574952 records/second 98 | FileLength : 3824 kb 99 | 100 | ``` 101 | -------------------------------------------------------------------------------- /References/LiteDBv3.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mbdavid/LiteDB-Perf/7c4e91129d992bd46c68326fd3525bcb4fc8e100/References/LiteDBv3.dll -------------------------------------------------------------------------------- /TestPerfLiteDB.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25420.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestPerfLiteDB", "TestPerfLiteDB\TestPerfLiteDB.csproj", "{54EBE560-C586-4255-B8FE-910AB9332103}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {54EBE560-C586-4255-B8FE-910AB9332103}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {54EBE560-C586-4255-B8FE-910AB9332103}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {54EBE560-C586-4255-B8FE-910AB9332103}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {54EBE560-C586-4255-B8FE-910AB9332103}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /TestPerfLiteDB/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 |
6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /TestPerfLiteDB/Engines/ITest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Data; 4 | using System.Data.SQLite; 5 | using System.Diagnostics; 6 | using System.IO; 7 | using System.Linq; 8 | using System.Text; 9 | using System.Threading.Tasks; 10 | using LiteDB; 11 | 12 | namespace TestPerfLiteDB 13 | { 14 | public interface ITest : IDisposable 15 | { 16 | int Count { get; } 17 | int FileLength { get; } 18 | 19 | void Prepare(); 20 | void Insert(); 21 | void Bulk(); 22 | void Update(); 23 | void CreateIndex(); 24 | void Query(); 25 | void Delete(); 26 | void Drop(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /TestPerfLiteDB/Engines/LiteDB_Test.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Data; 4 | using System.Data.SQLite; 5 | using System.Diagnostics; 6 | using System.IO; 7 | using System.Linq; 8 | using System.Text; 9 | using System.Threading.Tasks; 10 | using LiteDB; 11 | 12 | namespace TestPerfLiteDB 13 | { 14 | public class LiteDB_Test : ITest 15 | { 16 | private string _filename; 17 | private LiteEngine _db; 18 | private int _count; 19 | 20 | public int Count { get { return _count; } } 21 | public int FileLength { get { return (int)new FileInfo(_filename).Length; } } 22 | 23 | public LiteDB_Test(int count, string password, LiteDB.FileOptions options) 24 | { 25 | _count = count; 26 | _filename = "dblite-" + Guid.NewGuid().ToString("n") + ".db"; 27 | 28 | var disk = new FileDiskService(_filename, options); 29 | 30 | _db = new LiteEngine(disk, password); 31 | } 32 | 33 | public void Prepare() 34 | { 35 | } 36 | 37 | public void Insert() 38 | { 39 | foreach (var doc in Helper.GetDocs(_count)) 40 | { 41 | _db.Insert("col", doc); 42 | } 43 | } 44 | 45 | public void Bulk() 46 | { 47 | _db.Insert("col_bulk", Helper.GetDocs(_count)); 48 | } 49 | 50 | public void Update() 51 | { 52 | foreach(var doc in Helper.GetDocs(_count)) 53 | { 54 | _db.Update("col", doc); 55 | } 56 | } 57 | 58 | public void CreateIndex() 59 | { 60 | _db.EnsureIndex("col", "name", false); 61 | } 62 | 63 | public void Query() 64 | { 65 | for(var i = 0; i < _count; i++) 66 | { 67 | _db.Find("col", LiteDB.Query.EQ("_id", i)).Single(); 68 | } 69 | } 70 | 71 | public void Delete() 72 | { 73 | _db.Delete("col", LiteDB.Query.All()); 74 | } 75 | 76 | public void Drop() 77 | { 78 | _db.DropCollection("col_bulk"); 79 | } 80 | 81 | public void Dispose() 82 | { 83 | _db.Dispose(); 84 | File.Delete(_filename); 85 | } 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /TestPerfLiteDB/Engines/SQLite_Test.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Data; 4 | using System.Data.SQLite; 5 | using System.Diagnostics; 6 | using System.IO; 7 | using System.Linq; 8 | using System.Text; 9 | using System.Threading.Tasks; 10 | 11 | namespace TestPerfLiteDB 12 | { 13 | public class SQLite_Test : ITest 14 | { 15 | private string _filename; 16 | private SQLiteConnection _db; 17 | private int _count; 18 | 19 | public int Count { get { return _count; } } 20 | public int FileLength { get { return (int)new FileInfo(_filename).Length; } } 21 | 22 | public SQLite_Test(int count, string password, bool journal) 23 | { 24 | _count = count; 25 | _filename = "sqlite-" + Guid.NewGuid().ToString("n") + ".db"; 26 | var cs = "Data Source=" + _filename; 27 | if (password != null) cs += "; Password=" + password; 28 | if (journal == false) cs += "; Journal Mode=Off"; 29 | _db = new SQLiteConnection(cs); 30 | } 31 | 32 | public void Prepare() 33 | { 34 | _db.Open(); 35 | 36 | var table = new SQLiteCommand("CREATE TABLE col (id INTEGER NOT NULL PRIMARY KEY, name TEXT, lorem TEXT)", _db); 37 | table.ExecuteNonQuery(); 38 | 39 | var table2 = new SQLiteCommand("CREATE TABLE col_bulk (id INTEGER NOT NULL PRIMARY KEY, name TEXT, lorem TEXT)", _db); 40 | table2.ExecuteNonQuery(); 41 | } 42 | 43 | public void Insert() 44 | { 45 | var cmd = new SQLiteCommand("INSERT INTO col (id, name, lorem) VALUES (@id, @name, @lorem)", _db); 46 | 47 | cmd.Parameters.Add(new SQLiteParameter("id", DbType.Int32)); 48 | cmd.Parameters.Add(new SQLiteParameter("name", DbType.String)); 49 | cmd.Parameters.Add(new SQLiteParameter("lorem", DbType.String)); 50 | 51 | foreach (var doc in Helper.GetDocs(_count)) 52 | { 53 | cmd.Parameters["id"].Value = doc["_id"].AsInt32; 54 | cmd.Parameters["name"].Value = doc["name"].AsString; 55 | cmd.Parameters["lorem"].Value = doc["lorem"].AsString; 56 | 57 | cmd.ExecuteNonQuery(); 58 | } 59 | } 60 | 61 | public void Bulk() 62 | { 63 | using (var trans = _db.BeginTransaction()) 64 | { 65 | var cmd = new SQLiteCommand("INSERT INTO col_bulk (id, name, lorem) VALUES (@id, @name, @lorem)", _db); 66 | 67 | cmd.Parameters.Add(new SQLiteParameter("id", DbType.Int32)); 68 | cmd.Parameters.Add(new SQLiteParameter("name", DbType.String)); 69 | cmd.Parameters.Add(new SQLiteParameter("lorem", DbType.String)); 70 | 71 | foreach (var doc in Helper.GetDocs(_count)) 72 | { 73 | cmd.Parameters["id"].Value = doc["_id"].AsInt32; 74 | cmd.Parameters["name"].Value = doc["name"].AsString; 75 | cmd.Parameters["lorem"].Value = doc["lorem"].AsString; 76 | 77 | cmd.ExecuteNonQuery(); 78 | } 79 | 80 | trans.Commit(); 81 | } 82 | } 83 | 84 | public void Update() 85 | { 86 | var cmd = new SQLiteCommand("UPDATE col SET name = @name, lorem = @lorem WHERE id = @id", _db); 87 | 88 | cmd.Parameters.Add(new SQLiteParameter("id", DbType.Int32)); 89 | cmd.Parameters.Add(new SQLiteParameter("name", DbType.String)); 90 | cmd.Parameters.Add(new SQLiteParameter("lorem", DbType.String)); 91 | 92 | foreach (var doc in Helper.GetDocs(_count)) 93 | { 94 | cmd.Parameters["id"].Value = doc["_id"].AsInt32; 95 | cmd.Parameters["name"].Value = doc["name"].AsString; 96 | cmd.Parameters["lorem"].Value = doc["lorem"].AsString; 97 | 98 | cmd.ExecuteNonQuery(); 99 | } 100 | } 101 | 102 | public void CreateIndex() 103 | { 104 | var cmd = new SQLiteCommand("CREATE INDEX idx1 ON col (name)", _db); 105 | 106 | cmd.ExecuteNonQuery(); 107 | } 108 | 109 | public void Query() 110 | { 111 | var cmd = new SQLiteCommand("SELECT * FROM col WHERE id = @id", _db); 112 | 113 | cmd.Parameters.Add(new SQLiteParameter("id", DbType.Int32)); 114 | 115 | for (var i = 0; i < _count; i++) 116 | { 117 | cmd.Parameters["id"].Value = i; 118 | 119 | var r = cmd.ExecuteReader(); 120 | 121 | r.Read(); 122 | 123 | var name = r.GetString(1); 124 | var lorem = r.GetString(2); 125 | 126 | r.Close(); 127 | } 128 | } 129 | 130 | public void Delete() 131 | { 132 | var cmd = new SQLiteCommand("DELETE FROM col", _db); 133 | 134 | cmd.ExecuteNonQuery(); 135 | } 136 | 137 | public void Drop() 138 | { 139 | var cmd = new SQLiteCommand("DROP TABLE col_bulk", _db); 140 | 141 | cmd.ExecuteNonQuery(); 142 | } 143 | 144 | public void Dispose() 145 | { 146 | _db.Dispose(); 147 | } 148 | } 149 | } 150 | -------------------------------------------------------------------------------- /TestPerfLiteDB/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Data.SQLite; 4 | using System.Diagnostics; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | using LiteDB; 9 | 10 | namespace TestPerfLiteDB 11 | { 12 | class Program 13 | { 14 | static void Main(string[] args) 15 | { 16 | RunTest("LiteDB: default", new LiteDB_Test(5000, null, new FileOptions { Journal = true, FileMode = FileOpenMode.Shared })); 17 | RunTest("LiteDB: encrypted", new LiteDB_Test(5000, "mypass", new FileOptions { Journal = true, FileMode = FileOpenMode.Shared })); 18 | RunTest("LiteDB: exclusive no journal", new LiteDB_Test(5000, null, new FileOptions { Journal = false, FileMode = FileOpenMode.Exclusive })); 19 | 20 | RunTest("SQLite: default", new SQLite_Test(5000, null, true)); 21 | RunTest("SQLite: encrypted", new SQLite_Test(5000, "mypass", true)); 22 | RunTest("SQLite: no journal", new SQLite_Test(5000, null, false)); 23 | 24 | Console.ReadKey(); 25 | } 26 | 27 | static void RunTest(string name, ITest test) 28 | { 29 | var title = name + " - " + test.Count + " records"; 30 | Console.WriteLine(title); 31 | Console.WriteLine("=".PadLeft(title.Length, '=')); 32 | 33 | test.Prepare(); 34 | 35 | test.Run("Insert", test.Insert); 36 | test.Run("Bulk", test.Bulk); 37 | test.Run("Update", test.Update); 38 | test.Run("CreateIndex", test.CreateIndex); 39 | test.Run("Query", test.Query); 40 | test.Run("Delete", test.Delete); 41 | test.Run("Drop", test.Drop); 42 | 43 | Console.WriteLine("FileLength : " + Math.Round((double)test.FileLength / (double)1024, 2).ToString().PadLeft(5, ' ') + " kb"); 44 | 45 | test.Dispose(); 46 | 47 | Console.WriteLine(); 48 | 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /TestPerfLiteDB/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("TestPerfLiteDB")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("TestPerfLiteDB")] 13 | [assembly: AssemblyCopyright("Copyright © 2016")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("54ebe560-c586-4255-b8fe-910ab9332103")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /TestPerfLiteDB/TestPerfLiteDB.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {54EBE560-C586-4255-B8FE-910AB9332103} 8 | Exe 9 | Properties 10 | TestPerfLiteDB 11 | TestPerfLiteDB 12 | v4.6 13 | 512 14 | true 15 | 16 | 17 | 18 | 19 | AnyCPU 20 | true 21 | full 22 | false 23 | bin\Debug\ 24 | DEBUG;TRACE 25 | prompt 26 | 4 27 | 28 | 29 | AnyCPU 30 | pdbonly 31 | true 32 | bin\Release\ 33 | TRACE 34 | prompt 35 | 4 36 | 37 | 38 | 39 | False 40 | ..\..\LiteDB-dev\LiteDB\bin\Release\net35\LiteDB.dll 41 | 42 | 43 | 44 | 45 | 46 | ..\packages\System.Data.SQLite.Core.1.0.103\lib\net46\System.Data.SQLite.dll 47 | True 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | Designer 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. 71 | 72 | 73 | 74 | 81 | -------------------------------------------------------------------------------- /TestPerfLiteDB/Utils/Helper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Data.SQLite; 4 | using System.Diagnostics; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | using LiteDB; 9 | 10 | namespace TestPerfLiteDB 11 | { 12 | static class Helper 13 | { 14 | public static void Run(this ITest test, string name, Action action) 15 | { 16 | var sw = new Stopwatch(); 17 | 18 | sw.Start(); 19 | action(); 20 | sw.Stop(); 21 | 22 | var time = sw.ElapsedMilliseconds.ToString().PadLeft(5, ' '); 23 | var seg = Math.Round(test.Count / sw.Elapsed.TotalSeconds).ToString().PadLeft(8, ' '); 24 | 25 | Console.WriteLine(name.PadRight(15, ' ') + ": " + 26 | time + " ms - " + 27 | seg + " records/second"); 28 | } 29 | 30 | public static IEnumerable GetDocs(int count) 31 | { 32 | for(var i = 0; i < count; i++) 33 | { 34 | yield return new BsonDocument 35 | { 36 | { "_id", i }, 37 | { "name", Guid.NewGuid().ToString() }, 38 | { "lorem", LoremIpsum(3, 5, 2, 3, 3) } 39 | }; 40 | } 41 | } 42 | 43 | public static string LoremIpsum(int minWords, int maxWords, 44 | int minSentences, int maxSentences, 45 | int numParagraphs) 46 | { 47 | var words = new[] { "lorem", "ipsum", "dolor", "sit", "amet", "consectetuer", 48 | "adipiscing", "elit", "sed", "diam", "nonummy", "nibh", "euismod", 49 | "tincidunt", "ut", "laoreet", "dolore", "magna", "aliquam", "erat" }; 50 | 51 | var rand = new Random(DateTime.Now.Millisecond); 52 | var numSentences = rand.Next(maxSentences - minSentences) + minSentences + 1; 53 | var numWords = rand.Next(maxWords - minWords) + minWords + 1; 54 | 55 | var result = new StringBuilder(); 56 | 57 | for (int p = 0; p < numParagraphs; p++) 58 | { 59 | for (int s = 0; s < numSentences; s++) 60 | { 61 | for (int w = 0; w < numWords; w++) 62 | { 63 | if (w > 0) { result.Append(" "); } 64 | result.Append(words[rand.Next(words.Length)]); 65 | } 66 | result.Append(". "); 67 | } 68 | result.AppendLine(); 69 | } 70 | 71 | return result.ToString(); 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /TestPerfLiteDB/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | --------------------------------------------------------------------------------