简体   繁体   中英

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

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.

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.

So two commands are not equivilent. The difference should be the same as between -Include and -Filter . Filter is always faster, as it taps into File System provider, instead of filtering only after retrieving the files.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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