看起来开销最小。我使用以下代码运行了一些计时测试:
var localTimes = new List<long>();
var sharedTimes = new List<long>();
var stopwatch = new Stopwatch();
for (int i = 0; i < 1000; i++)
{
stopwatch.Start();
var bytes = File.ReadAllBytes(@"E:\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"E:\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"E:\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"E:\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"E:\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"E:\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"E:\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"E:\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"E:\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"E:\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"E:\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"E:\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"E:\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"E:\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"E:\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"E:\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"E:\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"E:\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"E:\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"E:\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"E:\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"E:\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"E:\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"E:\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"E:\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"E:\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"E:\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"E:\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"E:\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"E:\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"E:\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"E:\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"E:\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"E:\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"E:\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"E:\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"E:\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"E:\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"E:\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"E:\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"E:\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"E:\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"E:\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"E:\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"E:\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"E:\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"E:\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"E:\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"E:\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"E:\Shared\Template.xlsx");
stopwatch.Stop();
localTimes.Add(stopwatch.ElapsedTicks);
stopwatch.Start();
bytes = File.ReadAllBytes(@"\\localhost\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"\\localhost\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"\\localhost\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"\\localhost\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"\\localhost\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"\\localhost\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"\\localhost\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"\\localhost\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"\\localhost\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"\\localhost\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"\\localhost\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"\\localhost\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"\\localhost\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"\\localhost\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"\\localhost\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"\\localhost\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"\\localhost\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"\\localhost\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"\\localhost\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"\\localhost\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"\\localhost\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"\\localhost\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"\\localhost\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"\\localhost\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"\\localhost\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"\\localhost\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"\\localhost\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"\\localhost\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"\\localhost\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"\\localhost\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"\\localhost\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"\\localhost\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"\\localhost\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"\\localhost\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"\\localhost\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"\\localhost\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"\\localhost\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"\\localhost\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"\\localhost\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"\\localhost\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"\\localhost\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"\\localhost\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"\\localhost\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"\\localhost\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"\\localhost\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"\\localhost\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"\\localhost\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"\\localhost\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"\\localhost\Shared\Template.xlsx");
bytes = File.ReadAllBytes(@"\\localhost\Shared\Template.xlsx");
stopwatch.Stop();
sharedTimes.Add(stopwatch.ElapsedTicks);
}
Console.WriteLine("Local: avg={0}, 50k={1}", TimeSpan.FromTicks((long)localTimes.Average()/50), TimeSpan.FromTicks(localTimes.Sum()));
Console.WriteLine("Shared: avg={0}, 50k={1}", TimeSpan.FromTicks((long)sharedTimes.Average()/50), TimeSpan.FromTicks(sharedTimes.Sum()));
结果如下:
我的结论是这无关紧要。