相关疑难解决方法(0)

VB.NET中Dictionary(Of String,SomeReferenceType)的性能

从/到Dictionary(Of String,SomeReferenceType)读取/添加值的性能如何取决于已输入的记录数?我的意思是,当n变大时,O(1),O(log n),O(n)或其他方式的时间会增加吗?

Dim index As New Dictionary(Of String, SomeReferenceType)

' N entries added in a loop
' ...

Dim id As Integer = 123456789 ' 9-digit number
Dim key As String = id.ToString()
Dim value As New SomeReferenceType

index(key) = value ' Need to estimate this
value = index.TryGetValue(key) ' and this operations depending on N (for large N)
Run Code Online (Sandbox Code Playgroud)

此外,如果缺乏记忆会发生什么?我们应该在输入元素之前设置字典的容量,以避免在没有足够的内存空间的情况下复制它吗?这个操作需要多长时间(如果需要,将字典复制到新的地方)取决于N?

.net vb.net performance dictionary

7
推荐指数
1
解决办法
7735
查看次数

如何加速在SQL Server和C#中读取大量数据

我在我的数据库中有一个大约200,000个条目的视图.我正在阅读以下代码:

using (SqlConnection conn = new SqlConnection....)
{
    conn.Open();

    string query = "SELECT * FROM SP3DPROJECT.dbo.XSystemHierarchy";

    using (SqlCommand comm = new SqlCommand())
    {
        comm.CommandText = query;
        comm.Connection = conn;

        using (SqlDataReader reader = comm.ExecuteReader())
        {
            DateTime start = DateTime.Now;

            while (reader.Read())
            {
                // Code goes here, but for performance 
                // test I'm letting this empty
            }

            DateTime end = DateTime.Now;
            TimeSpan elapsed = (end- start).TotalSeconds;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

视图只有2列GUID类型.将ExecuteCommand()是非常快的,但while循环(甚至没有任何代码,只是循环)大约需要150秒.

有更好或更快的方法吗?

c# sql-server

6
推荐指数
1
解决办法
2761
查看次数

标签 统计

.net ×1

c# ×1

dictionary ×1

performance ×1

sql-server ×1

vb.net ×1