을, 나는에서는 FileInfo와 FileSystemObject를 비교했다. SSD 드라이브를 통과하는 데 걸리는 시간을 측정했습니다.
기본적으로 FileInfo는 FileSystemObject보다 약 3 배 빠릅니다.
test FileInfo Files: 489557 Directories: 66023
FileInfo traversal needed 12,07s
test FileSystemObject. Files: 489557 Directories: 66023
FileInfo traversal needed 38,59s
윈도우 API를 사용하여 시도 할 worthwile 수 있습니다 :
나는 지배 아웃 캐싱 효과를 내 시스템의 측정을 반복했다. 그러나 호출 및 매개 변수 전달은 마샬링 (Marshalling)으로 인해 성능 비용을 지불해야합니다.
자란 C 유틸리티는 SSD를 스캔하는 데 약 8 초가 필요합니다.
코드 :
using System;
using System.Linq;
using Scripting;
using System.Diagnostics;
using System.IO;
namespace akTest
{
class Program
{
static void Main(string[] args)
{
Stopwatch watch = new Stopwatch();
watch.Start();
testFileInfo(@"c:\");
watch.Stop();
o("FileInfo traversal needed " + (watch.ElapsedMilliseconds/1000.0).ToString("#.##") + "s");
watch.Start();
testFSO(@"c:\");
watch.Stop();
o("FileInfo traversal needed " + (watch.ElapsedMilliseconds/1000.0).ToString("#.##") + "s");
o("");
o("Ciao!");
}
static void o(string s)
{
Console.WriteLine(s);
}
static void testFileInfo(string dir)
{
DirectoryInfo di = new DirectoryInfo(dir);
long fileCount = 0;
long dirCount = 0;
long calls = 0;
o("Testing FileInfo");
WalkDirectoryTree(di, ref fileCount, ref dirCount, ref calls);
o("testFileInfo completed. Files: " + fileCount + " Directories: " + dirCount + " Calls: " + calls);
}
static void testFSO(string dir)
{
FileSystemObject fso = new FileSystemObject();
Folder folder = fso.GetFolder(dir);
long fileCount = 0;
long dirCount = 0;
long calls = 0;
o("Testing FSO");
WalkDirectoryTree(folder, ref fileCount, ref dirCount, ref calls);
o("testFSO completed. Files: " + fileCount + " Directories: " + dirCount + " Calls: " + calls);
}
static void WalkDirectoryTree(DirectoryInfo root, ref long fileCount, ref long dirCount, ref long calls)
{
FileInfo[] files = null;
DirectoryInfo[] subDirs = null;
if (++calls % 10000 == 0)
o("" + calls);
try
{
files = root.GetFiles("*.*");
if (files != null)
{
fileCount += files.Count();
subDirs = root.GetDirectories();
dirCount += subDirs.Count();
foreach (DirectoryInfo dirInfo in subDirs)
{
WalkDirectoryTree(dirInfo, ref fileCount, ref dirCount, ref calls);
}
}
}
catch (Exception)
{
}
}
static void WalkDirectoryTree(Folder root, ref long fileCount, ref long dirCount, ref long calls)
{
Files files = null;
Folders subDirs = null;
if (++calls % 10000 == 0)
o("" + calls);
try
{
files = root.Files;
if (files != null)
{
fileCount += files.Count;
subDirs = root.SubFolders;
dirCount += subDirs.Count;
foreach (Folder fd in subDirs)
{
WalkDirectoryTree(fd, ref fileCount, ref dirCount, ref calls);
}
}
}
catch (Exception)
{
}
}
}
}
어머나! 번개 빠른 답변 주셔서 감사합니다! 나는 그것을 시도 할 것이다. – sergeidave