Sorting and Filtering Custom Collections Performance Test
With respect to a question I was asked on lists@MsWebDev.org.uk in relation to performance impact on filtering large collections of objects.
I therefore created a simple windows application which contained a Label, Textbox, Button and Datagrid. On the Form_Load event I create a For…Next loop counting from 1 to 1000000 and in each iteration of the loop I create a new person object taken from the “Sorting and Filtering Custom Collections” articles and give it a Firstname of Firstname_iLoop.ToString and the same for the Lastname. I then add this person to a persons collection, once the looping has finished, I then set the DataGrids.DataSource property equal to the Persons collection.
The textbox is used to enter a string value for a Filter, for example: Firstname_51276. This is then passed as a parameter to the Persons.FilterByFirstname function. Just before I call FilterByFirstname, I get the DateTime.Now value and store it in a variable, I call FilterByFirstname function and immediately after the call, I record the DateTime.Now. The FilterByFirstname function returns a collection of Person objects that match the Filter criteria, this collection is then given to the DataGrid as it’s new datasource property.
The Label displays the Start date and time, the end date and time and the elapsed date and time between the two. The resulting elapsed time is coming back at approximately: 00:00:01.1214632.
I am running the test on a P4 2.66 GHz, with 512 Mb RAM and Windows XP Professional SP 2.
This is pretty impressive considering, we are filtering through 1 million objects.
You can download the test application from here