tags:

views:

28

answers:

1

I'm using GetTokenInformation with the TokenGroups flags to retrieve all the groups that a particular token is part of. I'm then looping through each of the returned SIDs and using LookupAccountSid to grab the user name and domain. I call LookupAccountSid twice: the first time to grab the size of the name and domain character arrays and the second time populates the allocated StringBuilders.

I'm getting very long delays. I've run ANTS to see what the issue was and found that if a user was part of 23 groups this that the entire sequence would take 15 seconds! The profiler points to the first call of LookupAccountSid and states that it was averaging 652 ms per call.

This is what the call looks like:

            LookupAccountSid(null, tokenGroups.Groups[i].SID, null, ref accountCount, null,
                             ref domainCount, out snu);

accountCount and domainCount are initialized to 0 prior to this call. In the end the call is working but this delay is way to long. What am I doing wrong?

+2  A: 

It is impossible to accurately measure time taken when running a profiler.

It is only useful when compared to all the times of other methods.

Run the call using Stopwatch as a timer without debugging info/attaching a debugger, and optimizations turned on.

Edit:

I have code that runs about 100 times longer when a profiler is attached (10 seconds) vs NGEN'd app (0.1 seconds).

leppie
Thanks. Will do.
Adam Driscoll
Whew. Problem was actually fixed by something else and I thought, because the profiler was slowing this down, that the bug was still creeping around. The execution now takes around 1-2 ms! Thanks for helping me with my ignorance. :)
Adam Driscoll