-
Notifications
You must be signed in to change notification settings - Fork 7.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Get-ChildItem to a file is 2x slower than CMD #12817
Comments
1- in your ps code you use pipeline and pipeline inn PS is not like pipeline in UNIX. with PS pipeline is very powerful but slow |
It is tracked in #3575 |
@p0W3RH311 @iSazonov using redirection instead of pipe, is even worse: PS C:\rnw> (Measure-Command { dir -Recurse C:\rnw > C:\temp\1.txt }).TotalSeconds
18.5898439 The fact that everything is an object doesn't matter, that's an implementation detail. If we are pushing people away from CMD and onto PS as a replacement, then its performance must be comparable, and any overhead must be pay-for-play, and not affect the general case where I don't use any of the objects explicitly. |
Yeah, redirection to a file in PS is identical to # Set-Content coerces the input to string instead of sending it through the formatter
Measure-Command {
Get-ChildItem -Recurse C:\rnw | Set-Content -Path C:\temp\1.txt
}
# Pull off the property you want to store; Out-File vs Set-Content here will be about the same
Measure-Command {
Get-ChildItem -Recurse C:\rnw |
Select-Object -Property FullName |
Out-File -Path C:\temp\1.txt
} The formatter exists for convenience and making the shell experience more user-friendly. If you don't want the overhead it brings, there are plenty of avenues available to you to speed things up. 🙂 |
function cmddir($dir){cmd /c dir /S $dir} Same speed, same functionality. |
@asklar What is a result for: |
PWSH> $PSversiontable Name Value PSVersion 7.1.0-preview.2 PWSH> (Measure-Command { CMD /c DIR /S 'C:\Program Files\PowerShell' > C:\temp\1.txt }).TotalSeconds |
For
|
For |
This issue has been marked as duplicate and has not had any activity for 1 day. It has been closed for housekeeping purposes. |
Steps to reproduce
takes 15.222019 seconds
whereas CMD:
command took 0:0:8.47 (8.47s total)
Expected behavior
Same performance as CMD.
Actual behavior
2x slower than CMD
Environment data
The text was updated successfully, but these errors were encountered: