PowerShell is slow (much slower than Python) in large Search/Replace operation?

前端 未结 5 1272
长情又很酷
长情又很酷 2021-02-02 12:41

I have 265 CSV files with over 4 million total records (lines), and need to do a search and replace in all the CSV files. I have a snippet of my PowerShell code below that does

5条回答
  •  渐次进展
    2021-02-02 13:03

    I see this a lot:

    $content | foreach {$_ -replace $SearchStr, $ReplaceStr} 
    

    The -replace operator will handle an entire array at once:

    $content -replace $SearchStr, $ReplaceStr
    

    and do it a lot faster than iterating through one element at a time. I suspect doing that may get you closer to an apples-to-apples comparison.

提交回复
热议问题