Array.Find on powershell array

前端 未结 5 861
耶瑟儿~
耶瑟儿~ 2021-02-13 11:28

How can I use the Array.Find method in powershell?

For example:

$a = 1,2,3,4,5
[Array]::Find($a, { args[0] -eq 3 })

gives



        
5条回答
  •  终归单人心
    2021-02-13 11:53

    This was run across ~6 million items in a system.array using both methods

    $s=get-date
    $([array]::FindALL($OPTArray,[Predicate[string]]{ $args[0] -match '^004400702(_\d{5})?' })).count
    $(New-TimeSpan -Start $s -End $(get-date)).TotalSeconds
    
    20 items
    33.2223219 seconds
    
    $s=get-date
    $($OPTArray | where { $_ -match '^004400702(_\d{5})?'}).count 
    $(New-TimeSpan -Start $s -End $(get-date)).TotalSeconds
    
    20 items
    102.1832173 seconds
    

提交回复
热议问题