Runtime of Foreach-Object vs Foreach loop

前端 未结 3 1550
被撕碎了的回忆
被撕碎了的回忆 2020-12-11 09:44

I want to do a progress bar of my script but then I need a total amount of folders.

Is there a significant runtime difference between:

Get-ChildItem          


        
3条回答
  •  忘掉有多难
    2020-12-11 09:54

    Yes, there is a performance difference. foreach is faster than ForEach-Object, but requires more memory, because all items ($folders) must be in memory. ForEach-Object processes one item at a time as they're passed through the pipeline, so it has a smaller memory footprint, but isn't as fast as foreach.

    See also.

提交回复
热议问题