What is the performance of filling and showing a very large customer class
If you have a customer class with 85 properties and you assign each property with a valu for 5000 customers, then add each customer to a list so you can show each costomer in a datagridview. How long should this process take from when pressing down a button and assigning the first customer until all the 5000 customers has been assigned a value and shown in the gridview?
I want to know how many minutes doese it to assign 85 properties for 5000 customers, then add the customers to a list and shows them in a gridview.
EDIT: Here is some code:
private string customerID;
public string CustomerID
{
get { return customerID; }
set { customerID= value; }
}
private int username;
public int UserName
{
get { return username; }
set { username= value; }
}
private string adress;
public string Adress
{
get { return adress; }
set { adress= value; }
}
In another class i use while and switch-statement to assign these开发者_StackOverflow中文版 values. In the while-statement, as long as there is customers i use a switch-statement like this:
switch (customers)
{
case "Customer ID":
try
{
cust.CustomerID = customerid;
}
catch
{
}
break;
case "User Name":
try
{
cust.UserName = username;
}
catch
{
}
break;
case "Adress":
try
{
cust.Adress = adress;
}
catch ()
{
}
break;
I assign the customer properties like this.
No idea how much time it will take, you should measure it. All I can say is that showing 5000 records in a grid on a single page is bad from ergonomic perspective. I would recommend you implementing a paging.
The real answer to your question: it depends.
I'd oppose the design of such a system, use lazy loading and paging instead. But suppose you'd do it, we can make a little calculation (change the numbers to your actual values):
Memory considerations
- 85 properties have to be assigned, let's say with 16 bytes, than this makes 1360 bytes
- A list contains pointers to each item, this makes 1360 + 4 (or 1360 + 8) = 1364 bytes
- 5000 * 1364 = 6820000
- Display in a DataGridView: overhead per row about 4000 bytes (you have to test this for yourself, part of it may be stored depending on scrolling): 27280000000 =
- That is 26GB
Now, I have a system with 64GB inside, 64 bits. It might take as little as a few seconds (assuming I won't scroll). Filling the 5000 rows can be less than a few milliseconds though, even on an average system (5000 records is not much).
Any system that doesn't have enough memory available will start paging (swapping to the physical page file). This becomes very slow, orders of magnitude. Remember that when playing with relatively large datasets.
Note: I assumed everything was random and you tried measuring the speed of the object itself. But if your data comes from a disk, a remote database or worse, a web service, this can take any time from seconds to hours.
Active directory
EDIT: in a late comment under Darin's answer, you talk about Active Directory. This is remote and your speed will likely depend more on AD than anything else. Add paging (i.e., only load what you want to show) and you should get reasonable performance.
Your code
You show a bit of your code. The try/catch around the settors: they don't do anything, there's nothing to catch. In terms of performance: you just showed the part that's not performance critical (unless any of those strings are huge, see my memory section above). The part that is slow, is your AD part.
Conclusion (so far)
Reconsider your design. Read the data in chunks of 10 or 20 records, and only request those fields / properties from AD that are actually needed to show. You can't show them all at once anyway. DataGridView has excellent features for paging, I suggest you use the paging events in combination with better loading of the data.
In answer to your remark about it suddenly taking much more time above 5000 records: measure the performance counters of each system, check memory, page faults, network. Or just don't read above 5000 records at once.
精彩评论