using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Threading.Tasks;
using System.IO.MemoryMappedFiles;
using System.Diagnostics;
namespace MMFs {
class Program {
static void Main(string[] args) {
int SIZE = 1000000;
//Random rnd = new Random();
//double[] rndv = new double[SIZE];
//for(int i = 0; i < rndv.Length; i++) {
// rndv[i] = rnd.NextDouble() * 10000;
//}
//using(BinaryWriter swr = new BinaryWriter(new FileStream(@"c:\randomdata.data", FileMode.Create, FileAccess.Write))) {
// for(int i = 0; i < rndv.Length; i++) {
// swr.Write(rndv[i]);
// }
//}
double[] dbldata = new double[SIZE];
MemoryMappedFile mmf = MemoryMappedFile.CreateFromFile(@"c:\randomdata.data");
MemoryMappedViewAccessor access = mmf.CreateViewAccessor();
int sizedbl = sizeof(double);
int pos = 0;
for(int i = 0; i < SIZE; i++) {
double bucket = 0;
access.Read<double>(pos, out bucket);
pos += sizedbl;
dbldata[i] = bucket;
}
Stopwatch sw = Stopwatch.StartNew();
pos = 0;
for(int i = 0; i < SIZE; i++) {
double bucket = 0;
access.Read<double>(pos, out bucket);
pos += sizedbl;
dbldata[i] = bucket;
}
sw.Stop();
Console.WriteLine(sw.ElapsedMilliseconds + ", " + (1000 * 60) / sw.ElapsedMilliseconds);
Console.ReadLine();
}
}
}
2014년 4월 22일 화요일
MMF 테스트
라벨:
.NET Framework