小编use*_*426的帖子

BinarySearch太慢了

怎么可能当我在SortedList上使用.net BinarySearch时,它需要的时间比我在同一个列表上使用我自己的二进制搜索方法要长得多?

使用.net binarysearch:

int ipos = MyList.Keys.ToList().BinarySearch(unSearchFor);

if (ipos >= 0)
{
    // exact target found at position "ipos"
    return MyList[unSearchFor];
}
else
{
    // Exact key not found: 
    // BinarySearch returns negative when the exact target is not found,
    // which is the bitwise complement of the next index in the list larger than the target.
    ipos = ~ipos;
    try
    {
        return MyList.Values[ipos - 1];
    }
    catch
    {
        return null;
    }
}
Run Code Online (Sandbox Code Playgroud)

我的二元搜索方法:

int nStart = 0;
int …
Run Code Online (Sandbox Code Playgroud)

.net c# performance binary-search

0
推荐指数
1
解决办法
312
查看次数

标签 统计

.net ×1

binary-search ×1

c# ×1

performance ×1