-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathSingleInsertFileSize.cs
43 lines (36 loc) · 1017 Bytes
/
SingleInsertFileSize.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
43
using System;
using System.IO;
namespace StringDB.PerformanceNumbers
{
public class SingleInsertFileSize
{
public void Run()
{
void Insert(IDatabase<string, string> db) => DoWrite(db, 128, 1024);
var size1 = GetSizeAfter(1, Insert);
var size2 = GetSizeAfter(50, Insert);
var size3 = GetSizeAfter(100, Insert);
Console.WriteLine($"Size after 1 single insert: {size1}");
Console.WriteLine($"Size after 50 single inserts: {size2}");
Console.WriteLine($"Size after 100 single inserts: {size3}");
}
public static long GetSizeAfter(int times, Action<IDatabase<string, string>> action)
{
using (var ms = new MemoryStream())
using (var db = StringDatabase.Create(ms))
{
for (var i = 0; i < times; i++)
{
action(db);
}
return ms.Length;
}
}
public static void DoWrite(IDatabase<string, string> db, int keySize, int valueSize)
{
var key = new string('X', keySize);
var value = new string('X', valueSize);
db.Insert(key, value);
}
}
}