Kathleen Dollard made an offhand comment a while back that List(Of T) should be a better option than DataTable in many cases.
Today, I finally got around to benchmarking some various flavors of DataTable vs. Dictionary.
Let me begin by stating the caveat that my benchmarks cover only the scenario where there is a known primary key that is the term used for DataTable.Select. I also only concerned myself with name/value pairs -- at the moment I'm really looking at a "lookup table" sort of scenario.
I covered three different cases. The first was using DataTable.Select ("Table Search" in the chart). The second was using an indexed DataTable, using DataTable.Rows.Find ("Indexed Search"). The final case was using a Dictionary(Of String, String). In the chart, I included both the overhead of creating the Dictionary as well as the cost of seraching it.
To get these benchmarks, I ran cases with 10, 50, 100, 500... 1 million records. Each entry had a key/value pair of KeyN, ValueN. I then selected a random record, and retrieved it from each of the three data structures.
The chart tells the story very nicely. Logarithmic time (in ticks) is on the vertical axis; the horizontal axis is the number of records in the dataset.
(chart to follow... techhnical issues with uploading the image...)
Essentially, every search using DataTable.Select is approximately five times the cost of creating the Dictionary... and after that inital cost, Dictionary searches are essentially free. In all fairness, DataTable.Rows.Find is much, much faster than DataTable.Select; however, the Dictionary has a flatter curve.
Print | posted @ Tuesday, August 26, 2008 4:22 PM