简体   繁体   English

对使用 gci 和 -filter 时的性能差异感到好奇

[英]Curious about performance difference when use gci with -filter

Just notice performance difference between below commands.请注意以下命令之间的性能差异。 Does anybody know why ?有人知道为什么吗? Just curious.只是好奇。

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

This is documented under -filter Parameter.这记录在-filter参数下。

- Filter - Filter

Specifies a filter to qualify the Path parameter.指定筛选器以限定 Path 参数。 The FileSystem provider is the only installed PowerShell provider that supports filters. FileSystem提供程序是唯一已安装的支持过滤器的 PowerShell 提供程序。 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.提供程序在 cmdlet 获取对象时应用过滤器,而不是在检索对象后让 PowerShell 过滤这些对象。 The filter string is passed to the .NET API to enumerate files .过滤器字符串被传递到 .NET API 以枚举文件 The API only supports * and ? API 仅支持 * 和 ? wildcards.通配符。

When you use tab completion after dash (-{tab}), first parameter being suggested is -Path and that's where your pattern is being passed on to.当您在破折号 (-{tab}) 后使用制表符-Path ,建议的第一个参数是-Path ,这就是您的模式被传递到的位置。

So two commands are not equivilent.所以两个命令是不等价的。 The difference should be the same as between -Include and -Filter .区别应该与-Include-Filter之间的区别相同。 Filter is always faster, as it taps into File System provider, instead of filtering only after retrieving the files.过滤器总是更快,因为它利用文件系统提供程序,而不是仅在检索文件后进行过滤。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM