Imagine we want to read data from a SQL Server database putting it in a generic object that can be used in a JSON API response. An ADO.NET DataReader should be faster and use less memory than a DataAdapter / DataTable approach. This post details some tests and what the differences are …
I’m going to test this on the Customers table within the Northwind database. I’ve created 5 copies of the Customers table with increasing number of rows within it.
A script to create the 5 Customers tables can be found here
The test app can be found here.
The test app reads the Customers tables that vary in size using both the DataTable and DataReader / DataAdapter approaches. The time to read the data and put it in a generic object is captured along with the memory taken by the DataTable object.
As you can see the difference is minimal for <100,000 rows.
|Rows||DataTable (ms)||DataReader (ms)||Difference (ms)||DataTable size (Mb)|