通过本地路径或UNC共享路径访问文件之间的性能是否有任何差异

时间:2017-08-17 21:43:04

标签: windows performance unc

我有一些托管在很多地方的模板文件,主要原因是每个模块都有相应的模板可在本地访问。

后来,我意识到这些文件是通过每个盒子的UNC共享路径使用的。

我的问题是: 通过本地路径而不是UNC路径访问本地文件之间是否存在性能差异?

1 个答案:

答案 0 :(得分:2)

看起来最小的开销。我使用以下代码运行了一些时序测试:

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()));

结果如下:

当地:平均= 00:00:00.0567284,50k = 00:47:16.4212917

分享:avg = 00:00:00.0568292,50k = 00:47:21.4612018

我的结论是,它并不重要。