-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
138 lines (100 loc) · 3.98 KB
/
Program.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
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
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using UndocumentedWindows;
namespace MappableFileStream
{
class Program
{
static bool Cancel = false;
static async Task Main(string[] args)
{
int SizeX, SizeY;
SizeX = SizeY = 2048;
var process = Process.GetCurrentProcess();
var max= (nint)(HybridHelper.GetOSMemory().ullAvailPhys * 0.5d);
process.MaxWorkingSet = (nint)(HybridHelper.GetOSMemory().ullAvailPhys * 0.5d);
// process.MinWorkingSet = (nint)(HybridHelper.GetOSMemory().ullAvailPhys * 0.5d);
MappableFileStreamManager.SetMaxMemory((ulong)(HybridHelper.GetOSMemory().ullAvailPhys * 0.3d));
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
DataSource volumeStart = new Volume(SizeX, SizeY, 1000);
List<DataSource> sources = new List<DataSource>();
sources.Add(volumeStart);
for (int i = 0; i < 10; i++)
{
Processor p = new Processor(volumeStart);
volumeStart = p;
sources.Add(p);
}
int currentCount = 0;
int lastCount = 0;
DateTime lastTime = DateTime.Now;
var headline = "{0,5} | {1,12} | {2,12}";
Timer timer = new Timer(callback);
Console.WriteLine(String.Format(headline,
"Count",
"WorkingSet",
"Avail. Phys"
));
void callback(object state)
{
if (lastCount == currentCount)
return;
int nowCount = currentCount;
var nowTime = DateTime.Now;
int diff = nowCount - lastCount;
TimeSpan diffTime = nowTime - lastTime;
lastCount = currentCount;
lastTime = nowTime;
process.Refresh();
using (MappableFileStreamManager.WaitForDataAccess())
{
Console.WriteLine(String.Format(headline,
nowCount,
HybridHelper.GetOSMemory().ullAvailPhys,//process.WorkingSet64,
(long)process.MaxWorkingSet
));
}
//-Items per s: { diff / diffTime.TotalSeconds} ({ HybridHelper.GetOSMemory().ullAvailPhys})
}
timer.Change(0, 1000);
Console.CancelKeyPress += ConsoleCancelEventHandler;
await Task.Run(() =>
{
Parallel.For(0, volumeStart.SizeZ, (i, loopState) =>
// for (int i = 0; i < volumeStart.SizeZ; i++)
{
var data = volumeStart.GetData(i);
Interlocked.Increment(ref currentCount);
if (Cancel)
{
loopState.Break();
return;
}
}
);
});
//Console.WriteLine($"{HybridFileStream<int>.Watch.Elapsed.TotalMilliseconds}ms");
Stopwatch disposeWatch = Stopwatch.StartNew();
volumeStart.Dispose();
foreach (var processor in sources)
processor.Dispose();
Console.WriteLine("Dispose: " + disposeWatch.Elapsed.TotalMilliseconds + "ms");
TimeSpan ts = stopWatch.Elapsed;
Console.WriteLine("RunTime: " + ts.TotalMilliseconds + "ms");
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Finished");
}
public static void ConsoleCancelEventHandler(object? sender, ConsoleCancelEventArgs e)
{
Cancel = true;
}
}
}