对将 gci 与 -filter 一起使用时的性能差异感到好奇

Curious about performance difference when use gci with -filter

请注意以下命令之间的性能差异。有人知道为什么吗?只是好奇。

 PS> gci -r *.txt          # this is slower
 PS> gci -r -filter *.txt  # this is faster

这记录在 -filter Parameter.

-Filter

Specifies a filter to qualify the Path parameter. The FileSystem provider is the only installed PowerShell provider that supports filters. Filters are more efficient than other parameters. The provider applies filter when the cmdlet gets the objects rather than having PowerShell filter the objects after they're retrieved. The filter string is passed to the .NET API to enumerate files. The API only supports * and ? wildcards.

当您在破折号 (-{tab}) 后使用制表符完成时,建议的第一个参数是 -Path,这就是您的模式被传递到的地方。

所以两个命令不等价。差异应与 -Include-Filter 之间的差异相同。过滤器总是更快,因为它利用文件系统提供程序,而不是仅在检索文件后才进行过滤。