Peter Ritchie Inc. Software Consulting Co. Home
      Downloads    General    .NET Topics    C++ Topics    C# Topics

Home
Products & Services
Articles/Blog
Downloads
Links
Members Only
Support
Contact
Login
Register
Performance Testing GenericPrincipal.IsInRole

Posted by on Saturday, February 11, 2006 (EST)

Gauge GenericPrincipal.IsInRole()'s suitability and scalability.

Overriding System.Security.Principal.GenericPrincipal is an easy way to get role-based permission management for declaratively and imperatively permission checks.  But, what performance consequences are there to using GenericPrincipal.IsInRole() and how does it affect design of permissions? 

Here are some performance metrics that I've created from simple experimental development:

GenericPrincipal.IsInRole() has worst-case cost of about 453.00 µs (microseconds, one-millionth of a second).

Context: Pentium 4 1.83GHz, role names with 34 characters in common.

Here is the code used to test (C#):

 String [] roles = new String[1000000];
 for(int i = 0; i < roles.Length; ++i)
 {
  roles[i] = "LongRoleNameHereForTestingPurposes" + i.ToString();
 }
 GenericPrincipal p = new GenericPrincipal(windowsPrincipal.Identity, roles);

 DateTime start = DateTime.Now;
 p.IsInRole("LongRoleNameHereForTestingPurposes" + (roles.Length + 1).ToString());
 TimeSpan span = DateTime.Now - start;

Obviously, regardless of design, minimizing the number of roles assigned at a given time will produce the highest performance solution.  It's clear from these results that GenericPrincipal is quite capable of dealing with many assigned roles without drastically affecting performance.


Average Rating:

Add Your Comment

Advertisement
Rent and Buy DVDs. No Late Fees. Click to join Today.

RSS Feed Temporarily Unavailable
Feed will retried at 8/28/2008 4:48:18 PM
Last Refreshed 8/28/2008 9:03:41 AM

 
Copyright © 2005, Peter A. Ritchie All rights reserved