Curl Powershell windows 10 比命令提示符慢为什么?
Curl Powershell windows 10 slower than command prompt why?
只是一个非常标准的 curl 命令调用 S3 端点以使用所有默认值进行下载。在 mac 上,或者在使用命令行的 PC 上,如果缓存在 cdn 上,我会得到 103MBsec,否则会得到 80mbsec。相同的命令,相同的存储桶,相同的对象,使用“curl.exe”,通过 powershell 调用时我得到 1MBSec。我猜 powershell 做了一些不同的事情让它变得很慢?我尝试使用最新的 curl 二进制文件,但还是一样。
我想我在使用 curl 命令时误解了 powershell 在做什么
curl.exe yourfileonS3 >> output.bin
请参阅 了解有关此的完整上下文(我建议接受那个!),重要的一点是在重定向中处理字节流 有问题且容易出错 在 PowerShell 中,应避免使用。
所以我调查了一下,我相信原因是 >>
(文件重定向)是缓慢的部分。
我最初怀疑你可能正在调用 curl
(它是 Windows PowerShell 中 Invoke-WebRequest
的别名),但我能够重现 [=14= 之间的速度差异] 直接在 PowerShell vs cmd.exe
中测量,这样:
# call curl.exe and do redirection in PowerShell
Measure-Command -Expression { curl.exe https://uploader.codecov.io/v0.1.0_6943/linux/codecov >> delme.bin }
del delme.bin
# call cmd.exe and do redirection there
Measure-Command -Expression { & cmd.exe /c 'curl.exe https://uploader.codecov.io/v0.1.0_6943/linux/codecov >> delme.bin' }
del delme.bin
这足以显示出明显的差异。
我还确认这个问题在 Windows PowerShell 中比后来的跨平台版本 (pwsh.exe
) 更严重。在Windows,7.1.0版本,上面同样的命令还是有很大的区别。
补充:
在 PowerShell 中,redirection operators >
and >>
are in effect aliases of Out-File
和 Out-File -Append
。
因此,>
和 >>
而不是 仅仅是字节流管道,事实上,从 v7.2 开始,PowerShell 不 支持将 原始字节输出 发送到文件。
相反,PowerShell 总是 将任何外部程序的输出解码为 text([string]
个实例),基于 [Console]::OutputEncoding]
报告的字符编码,然后使用 Out-File
保存到目标文件(可能通过 >
/ >>
),重新编码这些字符串,使用该 cmdlet 的默认字符编码(除非在显式 Out-File
调用中被 -Encoding
覆盖)。
这不仅没有保留外部程序的原始字节
输出,它增加了显着的开销。
要获取原始字节处理,请调用 cmd.exe
[1] 并使用 its 重定向运算符:
cmd /c 'curl.exe yourfileonS3 >> output.bin'
有关详细信息,请参阅 。
[1] 在类 Unix 平台上,使用 sh -c 'curl yourfileonS3 >> output.bin'
只是一个非常标准的 curl 命令调用 S3 端点以使用所有默认值进行下载。在 mac 上,或者在使用命令行的 PC 上,如果缓存在 cdn 上,我会得到 103MBsec,否则会得到 80mbsec。相同的命令,相同的存储桶,相同的对象,使用“curl.exe”,通过 powershell 调用时我得到 1MBSec。我猜 powershell 做了一些不同的事情让它变得很慢?我尝试使用最新的 curl 二进制文件,但还是一样。 我想我在使用 curl 命令时误解了 powershell 在做什么
curl.exe yourfileonS3 >> output.bin
请参阅
所以我调查了一下,我相信原因是 >>
(文件重定向)是缓慢的部分。
我最初怀疑你可能正在调用 curl
(它是 Windows PowerShell 中 Invoke-WebRequest
的别名),但我能够重现 [=14= 之间的速度差异] 直接在 PowerShell vs cmd.exe
中测量,这样:
# call curl.exe and do redirection in PowerShell
Measure-Command -Expression { curl.exe https://uploader.codecov.io/v0.1.0_6943/linux/codecov >> delme.bin }
del delme.bin
# call cmd.exe and do redirection there
Measure-Command -Expression { & cmd.exe /c 'curl.exe https://uploader.codecov.io/v0.1.0_6943/linux/codecov >> delme.bin' }
del delme.bin
这足以显示出明显的差异。
我还确认这个问题在 Windows PowerShell 中比后来的跨平台版本 (pwsh.exe
) 更严重。在Windows,7.1.0版本,上面同样的命令还是有很大的区别。
补充
在 PowerShell 中,redirection operators
>
and>>
are in effect aliases ofOut-File
和Out-File -Append
。
因此,>
和>>
而不是 仅仅是字节流管道,事实上,从 v7.2 开始,PowerShell 不 支持将 原始字节输出 发送到文件。相反,PowerShell 总是 将任何外部程序的输出解码为 text(
[string]
个实例),基于[Console]::OutputEncoding]
报告的字符编码,然后使用Out-File
保存到目标文件(可能通过>
/>>
),重新编码这些字符串,使用该 cmdlet 的默认字符编码(除非在显式Out-File
调用中被-Encoding
覆盖)。这不仅没有保留外部程序的原始字节 输出,它增加了显着的开销。
要获取原始字节处理,请调用 cmd.exe
[1] 并使用 its 重定向运算符:
cmd /c 'curl.exe yourfileonS3 >> output.bin'
有关详细信息,请参阅
[1] 在类 Unix 平台上,使用 sh -c 'curl yourfileonS3 >> output.bin'