Runtime of Foreach-Object vs Foreach loop

前端 未结 3 1541
被撕碎了的回忆
被撕碎了的回忆 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 10:13

    You can check for yourself:

    Measure-Command {
        1..100000 | ForEach-Object $_
    }
    
    1.17s
    
    Measure-Command {
        foreach ($i in (1..100000))
        {
        $i
        }
    }
    
    0.15s
    

提交回复
热议问题