通过本地路径访问文件或访问 UNC 共享路径在性能上是否存在差异
Is there any difference in performance between accessing a file through local path or to UNC shared path
我有几个模板文件托管在很多地方,主要原因是每个模块都有相应的本地可访问模板。
后来,我意识到这些文件是通过每个盒子的 UNC 共享路径使用的。
我的问题是:
通过本地路径访问本地文件与通过 UNC 路径访问本地文件有什么性能差异吗?
看起来开销最小。我 运行 使用以下代码进行一些计时测试:
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
我的结论是没关系。
我有几个模板文件托管在很多地方,主要原因是每个模块都有相应的本地可访问模板。
后来,我意识到这些文件是通过每个盒子的 UNC 共享路径使用的。
我的问题是: 通过本地路径访问本地文件与通过 UNC 路径访问本地文件有什么性能差异吗?
看起来开销最小。我 运行 使用以下代码进行一些计时测试:
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
我的结论是没关系。