-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathProgram.cs
More file actions
139 lines (131 loc) · 3.79 KB
/
Program.cs
File metadata and controls
139 lines (131 loc) · 3.79 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using FriendlyCSharp.Databases;
namespace FcsInmemStream.Multi.sample
{
class Program
{
public unsafe struct StructIms : ICloneable
{
public int key;
public uint value;
//
public DateTime dt;
//
public Guid guid;
//
public fixed byte buff[32]; // 4064, 992, 480, 224, 96, 32
public object Clone()
{
return base.MemberwiseClone();
}
}
static void Main(string[] args)
{
Console.OutputEncoding = System.Text.Encoding.UTF8;
Console.WriteLine(String.Format("FcsInmemStream.Multi.sample, {0}", (IntPtr.Size == 4) ? "32 bit" : "64 bit"));
Console.WriteLine("------------------------------------");
int iSizeT = Marshal.SizeOf(default(StructIms));
int iRepeat = 6000;
if (iSizeT > 128)
iRepeat = 4000;
else if (iSizeT > 1024)
iRepeat = 1000;
int iID = 0;
int cacheCount = 1000;
StructIms[] aIms = new StructIms[cacheCount];
FcsInmemStream<StructIms>.ImsEnumeratorCacheLen = 128;
FcsInmemStream<StructIms> ims = FcsInmemStream<StructIms>.Open(-4);
#if DEBUG
ims.FuncException = true;
#else
ims.FuncException = false;
#endif
Stopwatch swX = new Stopwatch();
for (int te = 0; te < iRepeat; te++)
{
for (int ui = 0; ui < cacheCount; ui++)
{
aIms[ui].key = iID++;
aIms[ui].value = 0;
aIms[ui].dt = DateTime.Now;
aIms[ui].guid = Guid.NewGuid();
}
swX.Start();
ims.Append(aIms);
swX.Stop();
}
Console.WriteLine($"Records: {ims.Length} | size: {iSizeT} Byte");
Console.WriteLine("\nAppend IOPS: {0,13:N0} [{1:N7} s] | count: {2,10:N0}", iID / swX.Elapsed.TotalSeconds, swX.Elapsed.TotalSeconds, iID);
// foreach()
iID = 0;
foreach (StructIms value in ims)
{
if (value.key != iID)
break;
iID++;
}
iID = 0;
swX.Reset();
swX.Start();
foreach (StructIms value in ims)
{
if (value.key != iID)
break;
iID++;
}
swX.Stop();
Console.WriteLine("foreach IOPS: {0,13:N0} [{1:N7} s] | count: {2,10:N0}", iID / swX.Elapsed.TotalSeconds, swX.Elapsed.TotalSeconds, iID);
// Write()
uint pos = 0;
while (pos < ims.Length)
{
int iRead = ims.Read(pos, aIms, (UInt16)cacheCount);
pos += (uint)iRead;
}
Array.Clear(aIms, 0, aIms.Length);
iID = 0;
pos = 0;
swX.Reset();
while (pos < ims.Length)
{
ims.Read(pos, aIms, (UInt16)cacheCount);
for (int ui = 0; ui < cacheCount; ui++)
{
aIms[ui].key *= 10;
iID++;
}
swX.Start();
ims.Write(pos, aIms, null, 0, (UInt16)cacheCount);
swX.Stop();
pos += (uint)cacheCount;
}
Console.WriteLine("Write IOPS: {0,13:N0} [{1:N7} s] | count: {2,10:N0}", iID / swX.Elapsed.TotalSeconds, swX.Elapsed.TotalSeconds, iID);
// Read()
Array.Clear(aIms, 0, aIms.Length);
iID = 0;
pos = 0;
swX.Reset();
while (pos < ims.Length)
{
swX.Start();
int iRead = ims.Read(pos, aIms, (UInt16)cacheCount);
swX.Stop();
pos += (uint)iRead;
for (int ui = 0; ui < iRead; ui++)
{
if (aIms[ui].key != iID)
break;
iID += 10;
}
}
iID /= 10;
Console.WriteLine("Read IOPS: {0,13:N0} [{1:N7} s] | count: {2,10:N0}", iID / swX.Elapsed.TotalSeconds, swX.Elapsed.TotalSeconds, iID);
ims.Close();
Console.WriteLine("------------------------------------");
Console.WriteLine("Key ENTER press.");
Console.ReadLine();
}
}
}