mardi, octobre 25, 2005

ADO.net 2, New Indexing Engine

The indexing engine for the DataTable has been completely rewritten in ADO.NET 2.0 and scales much better for large datasets. This results in faster basic inserts, updates, and deletes, and therefore faster Fill and Merge operations. While benchmarks and quantifying performance gains is always an application-specific and often risky affair, these improvements clearly provide more than an order of magnitude improvement in loading a DataTable with a million rows.

When I try to create a new dataset, then insert 1 millions of rows :
Dim ds As New DataSet
Dim i As Integer

Dim dr As DataRow

ds.Tables.Add("BigTable")
ds.Tables(0).Columns.Add("ID", Type.GetType("System.Int32"))
ds.Tables(0).Columns("ID").Unique = True
ds.Tables(0).Columns.Add("Value", Type.GetType("System.Int32"))

Dim rand As New Random
Dim value As Integer

For i = 1 To 1000000
Try
value = rand.Next
dr = ds.Tables(0).NewRow()
dr("ID") = value

dr("Value") = value
ds.Tables(0).Rows.Add(dr)
Catch ex As Exception
End Try

Next

In environment with ADO.NET 1.1 and Visual Studio 2003, the execution time was about 30 minutes. With ADO.NET 2.0 and Visual Studio 2005, I had an execution time of approximately 40-50 seconds! When I lowered the number of rows to only half a million, the 1.1 version took about 45 seconds and the 2.0 version took about 20 seconds. Your numbers will vary, but I think the point is clear.

From Microsoft MSDN

Aucun commentaire: