I did try a loop similar to what you described (at the suggestion of another
poster).  Everything took longer yesterday since I was running it over a DSL
connection (VPN into work), but things took longer with just the property
references than they did with property references and row operations.

I tried it again when I came into work this morning, and the loop you
described took about 15 seconds to run.  When I switched it back to working
code that did row operations too, it only took about 12 seconds.

On Wed, 7 Jan 2004 11:57:02 -0500, J. Merrill <[EMAIL PROTECTED]> wrote:

>As someone else pointed out, and I don't remember seeing you acknowledge
the point, you haven't AFAICT determined whether the code you've got is slow
because it's creating and adding many DataRow objects to your ArrayList, or
if it's slow because of the loop through the userList objects and
referencing the various user properties.  If you modify the code block that
you've determined is slow -- the one defined by the loop
>  foreach (UserDirectoryObject user in userList)
>-- so that you don't actually do anything with DataRows or the ArrayList,
but just reference the properties of the user object, and see how long that
takes, you'll know whether the time is taken while by accessing the userList
data or if it's in your code.  Perhaps --
>
>  {
>    maxl = Math.Max(maxl, length(user.lastName);
>    maxl = Math.Max(maxl, length(user.firstName);
>    /* etc */
>  }
>
>having added a line
>    int maxl = 0;
>before the loop block, and displaying it after.  (The reason I suggest
creating and displaying the maxl value is so that the compiler doesn't
optimize away all the access to user objects when it sees that none of the
values are being used.)
>
>If it's accessing the userList info that takes the time, it's someone
else's code that needs to run faster, not yours.  Good luck.
>
>At 02:08 PM 1/6/2004, Scott A. Lawrence wrote
>>I'm writing a user profile tool that manipulates information in an LDAP
>>server.  I'm using an abstraction layer that talks directly to the server
>>(written by another developer).  The function of the abstraction layer that
>>returns a list of all the users in LDAP returns an ArrayList.  For easier
>>filtering and sorting of this data, I build a DataTable in code, returning
>>its default view so it can be bound to a DataGrid.
>>
>>The app currently takes between 15-20 seconds to load approximately 800
>>users from the LDAP source into memory, cache the user information, and
>>display the page (DataGrid displays 20 users per page).  The vast majority
>>of that time (13-18 seconds) is consumed by the foreach loop that puts each
>>ArrayList element into the
>>
>>The code in question looks like the following:
>>
>>ArrayList userList = theDirectory.getUsers();
>>
>>if (userList != null)
>>{
>>  foreach (UserDirectoryObject user in userList)
>>  {
>>    DataRow drUser = tblUsers.NewRow();
>>    drUser["lastName"] = user.lastName;
>>    drUser["firstName"] = user.firstName;
>>    /* etc */
>>    tblUsers.Rows.Add(drUser);
>>  }
>>}
>>
>>tblUsers.DefaultView.Sort = "lastName";
>>return tblUsers.DefaultView
>>
>>
>>Any suggestions about how to increase the speed of this would be greatly
>>appreciated.
>>
>>Thanks!

===================================
This list is hosted by DevelopMentorŪ  http://www.develop.com
Some .NET courses you may be interested in:

NEW! Guerrilla ASP.NET, 26 Jan 2004, in Los Angeles
http://www.develop.com/courses/gaspdotnetls

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to