Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Performance Powershell问题-寻找通过500k对象循环的最快方法,在另一个500k对象数组中查找匹配项_Performance_Powershell_Large Data - Fatal编程技术网

Performance Powershell问题-寻找通过500k对象循环的最快方法,在另一个500k对象数组中查找匹配项

Performance Powershell问题-寻找通过500k对象循环的最快方法,在另一个500k对象数组中查找匹配项,performance,powershell,large-data,Performance,Powershell,Large Data,我使用import-csv cmdlet导入了两个大的.csv文件。我已经做了很多的搜索和尝试,最后我发帖寻求一些帮助,使这更容易 我需要遍历第一个数组,它的行数从80k到500k不等。这些数组中的每个对象都有多个属性,然后我需要在第二个数组中找到相应的条目,该数组的大小与其中的属性相同 我将它们作为[systems.collection.arrayList]导入,并尝试将它们作为哈希表放置。我甚至试着和LINQ混在一起,这在其他几篇文章中都提到过 有没有可能任何人都可以提供建议或见解,如何让这

我使用import-csv cmdlet导入了两个大的.csv文件。我已经做了很多的搜索和尝试,最后我发帖寻求一些帮助,使这更容易

我需要遍历第一个数组,它的行数从80k到500k不等。这些数组中的每个对象都有多个属性,然后我需要在第二个数组中找到相应的条目,该数组的大小与其中的属性相同

我将它们作为[systems.collection.arrayList]导入,并尝试将它们作为哈希表放置。我甚至试着和LINQ混在一起,这在其他几篇文章中都提到过

有没有可能任何人都可以提供建议或见解,如何让这项工作运行得更快?感觉就像我在一个干草堆里寻找另一个干草堆里的干草

$ImportTime1 = Measure-Command {
    [System.Collections.ArrayList]$fileList1 = Import-csv file1.csv
    [System.Collections.ArrayList]$fileSorted1 = ($fileList1 | Sort-Object -property 'Property1' -Unique -Descending)
    Remove-Variable fileList1
}

$ImportTime2 = Measure-Command {
    [System.Collections.ArrayList]$fileList2 = Import-csv file2.csv
    [System.Collections.ArrayList]$fileSorted2 = ($fileList2 | Sort-Object -property 'Property1' -Unique -Descending)
    Remove-Variable fileList2
}

$fileSorted1.foreach({
     $varible1 = $_
     $target = $fileSorted2.where({$_ -eq $variable1})
     ###do some other stuff
})
这可能有助于:

注释#27359中的更新解决方案+在注释#27380中添加Max Kozlov建议的更改


将列表传递到此哈希表应该很快,而且迭代也很快。

这是否回答了您的问题?和中提到的链接:。如果您正在寻找现成的LINQ解决方案,请尝试:
Join Object
from。通常,性能结果可能取决于您的输入,甚至取决于您的(预期的)输出对象(请参见:),这意味着除了您尝试的更具体示例外,最好添加一些示例输入数据和预期输出(另请参见:)。
Function RJ-CombinedCompare() {
    [CmdletBinding()]
    PARAM(
        [Parameter(Mandatory=$True)]$List1,
        [Parameter(Mandatory=$True)]$L1Match,
        [Parameter(Mandatory=$True)]$List2,
        [Parameter(Mandatory=$True)]$L2Match
    )
    $hash = @{}
    foreach ($data in $List1) {$hash[$data.$L1Match] += ,[pscustomobject]@{Owner=1;Value=$($data)}}
    foreach ($data in $List2) {$hash[$data.$L2Match] += ,[pscustomobject]@{Owner=2;Value=$($data)}}
    foreach ($kv in $hash.GetEnumerator()) {
        $m1, $m2 = $kv.Value.where({$_.Owner -eq 1}, 'Split')
        [PSCustomObject]@{
            MatchValue = $kv.Key
            L1Matches = $m1.Count
            L2Matches = $m2.Count
            L1MatchObject = $L1Match
            L2MatchObject = $L2Match
            List1 = $m1.Value
            List2 = $m2.Value
        }
    }
}

$fileList1 = Import-csv file1.csv
$fileList2 = Import-csv file2.csv

$newList = RJ-CombinedCompare -List1 $fileList1 -L1Match $(yourcolumnhere) -List2 $fileList2 -L2Match $(yourothercolumnhere)

foreach ($item in $newList) {
    # your logic here
}