forked from litedb-org/LiteDB
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Code cleanup in benchmarks and fixed formatting
- Loading branch information
1 parent
c0ced57
commit 67c4d34
Showing
12 changed files
with
703 additions
and
688 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
130 changes: 65 additions & 65 deletions
130
LiteDB.Benchmarks/Benchmarks/Insertion/InsertionBasicBenchmark.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,87 +1,87 @@ | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using BenchmarkDotNet.Attributes; | ||
using LiteDB.Benchmarks.Models; | ||
using LiteDB.Benchmarks.Models.Generators; | ||
|
||
namespace LiteDB.Benchmarks.Benchmarks.Insertion | ||
{ | ||
[BenchmarkCategory(Constants.Categories.INSERTION)] | ||
public class InsertionBasicBenchmark : BenchmarkBase | ||
{ | ||
private List<FileMetaBase> data; | ||
[BenchmarkCategory(Constants.Categories.INSERTION)] | ||
public class InsertionBasicBenchmark : BenchmarkBase | ||
{ | ||
private List<FileMetaBase> _data; | ||
private ILiteCollection<FileMetaBase> _fileMetaCollection; | ||
|
||
private ILiteCollection<FileMetaBase> _fileMetaCollection { get; set; } | ||
[GlobalSetup] | ||
public void GlobalSetup() | ||
{ | ||
File.Delete(DatabasePath); | ||
|
||
[GlobalSetup] | ||
public void GlobalSetup() | ||
{ | ||
File.Delete(DatabasePath); | ||
DatabaseInstance = new LiteDatabase(ConnectionString()); | ||
_fileMetaCollection = DatabaseInstance.GetCollection<FileMetaBase>(); | ||
|
||
DatabaseInstance = new LiteDatabase(ConnectionString()); | ||
_fileMetaCollection = DatabaseInstance.GetCollection<FileMetaBase>(); | ||
_data = FileMetaGenerator<FileMetaBase>.GenerateList(DatasetSize); // executed once per each N value | ||
} | ||
|
||
data = FileMetaGenerator<FileMetaBase>.GenerateList(DatasetSize); // executed once per each N value | ||
} | ||
[Benchmark(Baseline = true)] | ||
public int Insertion() | ||
{ | ||
var count = _fileMetaCollection.Insert(_data); | ||
DatabaseInstance.Checkpoint(); | ||
return count; | ||
} | ||
|
||
[Benchmark(Baseline = true)] | ||
public int Insertion() | ||
{ | ||
var count = _fileMetaCollection.Insert(data); | ||
DatabaseInstance.Checkpoint(); | ||
return count; | ||
} | ||
[Benchmark] | ||
public void InsertionWithLoop() | ||
{ | ||
// ReSharper disable once ForCanBeConvertedToForeach | ||
for (var i = 0; i < _data.Count; i++) | ||
{ | ||
_fileMetaCollection.Insert(_data[i]); | ||
} | ||
|
||
[Benchmark] | ||
public void InsertionWithLoop() | ||
{ | ||
// ReSharper disable once ForCanBeConvertedToForeach | ||
for (var i = 0; i < data.Count; i++) | ||
{ | ||
_fileMetaCollection.Insert(data[i]); | ||
} | ||
DatabaseInstance.Checkpoint(); | ||
} | ||
DatabaseInstance.Checkpoint(); | ||
} | ||
|
||
[Benchmark] | ||
public int Upsertion() | ||
{ | ||
var count = _fileMetaCollection.Upsert(data); | ||
DatabaseInstance.Checkpoint(); | ||
return count; | ||
} | ||
[Benchmark] | ||
public int Upsertion() | ||
{ | ||
var count = _fileMetaCollection.Upsert(_data); | ||
DatabaseInstance.Checkpoint(); | ||
return count; | ||
} | ||
|
||
[Benchmark] | ||
public void UpsertionWithLoop() | ||
{ | ||
// ReSharper disable once ForCanBeConvertedToForeach | ||
for (var i = 0; i < data.Count; i++) | ||
{ | ||
_fileMetaCollection.Upsert(data[i]); | ||
} | ||
DatabaseInstance.Checkpoint(); | ||
} | ||
[Benchmark] | ||
public void UpsertionWithLoop() | ||
{ | ||
// ReSharper disable once ForCanBeConvertedToForeach | ||
for (var i = 0; i < _data.Count; i++) | ||
{ | ||
_fileMetaCollection.Upsert(_data[i]); | ||
} | ||
|
||
[IterationCleanup] | ||
public void IterationCleanup() | ||
{ | ||
const string collectionName = nameof(FileMetaBase); | ||
DatabaseInstance.Checkpoint(); | ||
} | ||
|
||
DatabaseInstance.DropCollection(collectionName); | ||
[IterationCleanup] | ||
public void IterationCleanup() | ||
{ | ||
const string collectionName = nameof(FileMetaBase); | ||
|
||
DatabaseInstance.Checkpoint(); | ||
DatabaseInstance.Rebuild(); | ||
} | ||
DatabaseInstance.DropCollection(collectionName); | ||
|
||
[GlobalCleanup] | ||
public void GlobalCleanup() | ||
{ | ||
DatabaseInstance.DropCollection(nameof(FileMetaBase)); | ||
DatabaseInstance.Checkpoint(); | ||
DatabaseInstance.Dispose(); | ||
DatabaseInstance.Checkpoint(); | ||
DatabaseInstance.Rebuild(); | ||
} | ||
|
||
File.Delete(DatabasePath); | ||
} | ||
} | ||
[GlobalCleanup] | ||
public void GlobalCleanup() | ||
{ | ||
DatabaseInstance?.Checkpoint(); | ||
DatabaseInstance?.Dispose(); | ||
DatabaseInstance = null; | ||
|
||
File.Delete(DatabasePath); | ||
} | ||
} | ||
} |
Oops, something went wrong.