-
Notifications
You must be signed in to change notification settings - Fork 0
/
MyLiteDb.cs
42 lines (34 loc) · 1.02 KB
/
MyLiteDb.cs
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using System.Diagnostics;
using LiteDB;
namespace DbBench;
public class MyLiteDb : BenchDb
{
public override Task BenchWrite()
{
using var db = new LiteDatabase(GetDatabaseStoragePath());
var col = db.GetCollection<CommonRecord>(nameof(CommonRecord));
col.DeleteAll();
foreach (var numb in Enumerable.Range(0, NumberOfDocs))
{
col.Insert(new CommonRecord()
{
Name = "John",
Age = numb,
Timestamp = DateTimeOffset.UtcNow.ToUnixTimeSeconds()
});
}
return Task.CompletedTask;
}
public override Task<int> BenchRead()
{
using var db = new LiteDatabase(GetDatabaseStoragePath());
var col = db.GetCollection<CommonRecord>(nameof(CommonRecord));
var total = 0;
foreach (var realmBench in col.Query().ToEnumerable())
{
total += realmBench.Age;
}
Debug.WriteLine(total);
return Task.FromResult(total);
}
}