I just found out a HUGE performance difference between these two. Tested on my cheap laptop (HP Compaq 615 : AMD Turion Dual core 2,2GHz, 3GB RAM, 7200 RPM HDD; 500$) on .NET 4.0 Beta2 after several test runs (averaged results), 1 million iterations, release mode and Stopwatch for time measurement (as opposed to DateTime.Now) :

var a = Request.UserHostAddress; // -> 240 microseconds

var a = Request.ServerVariables["REMOTE_ADDR"]; // -> 0,4 microseconds

What the f...rick?! 500x times faster?

What does Request.UserHostAddress to use so much more time? Let's fire up good ol' Reflector :

	public string get_UserHostAddress()	
	{	    
	if (this._wr != null)	    
	{	        
	return this._wr.GetRemoteAddress();	    
	}	    
	return null;	
	}	
	

_wr is a HttpWorkerRequest (a public abstract class). The GetRemoteAddress is also abstract so I can't guess from Reflector. So I fired up Visual Studio 2010 again and saw that _wr was a Microsoft.VisualStudio.WebHost.Request instance. So much for my astonishment.. If it's hosted in the IDE it can be slow..

I still ponder if it's worth testing in a production environment whether it's faster or not (Request.UserHostAddress) significantly or not..

 

EDIT1 : Couldn't wait to test this at work under IIS 6.0 (Windows Server 2003, Intel Core2Duo 2,4 GHz, 4GB RAM) and Request.UserHostAddress takes 86 nanoseconds to be queried... Can't wait to get home and test again on IIS 7.5 (Windows 7 Ultimate RC)

 EDIT2: At home on IIS7.5, same laptop, release mode etc. etc. 29 microseconds for Request.UserHostAddress. It's better than Cassini's 240 microseconds but it should have been at most 100 nanoseconds...that's one thousand times slower..