minor speed optimization, converting NameValueCollection to ExpandoObject #140

wants to merge 1 commit into


None yet
3 participants

No description provided.

Interesting. Did you measure this with some profiling tool? I like the Linq version by Rob because it only defines the "what" and lets Linq decide about the "how". But since this method might be called a lot of times any improvement in speed can be valuable, and I must say that is easier to read too...


mountain65 commented May 6, 2012

Sorry, I just noticed that this discussion has been done before by you and Rob.


robconery commented May 14, 2012

How is this an optimization? What is it optimizing? How do you know the CLR isn't optimizing it already?

robconery#135 (comment)

On my machine - 5000 conversions of 200 elements NameValueCollection:

5042.2884 ms for nv.Cast().Select( key => new KeyValuePair( key, nv[ key ] ) ).ToList().ForEach( i => d.Add( i ) );
4993.2856 ms for nv.AllKeys.Select( key => new KeyValuePair( key, nv[ key ] ) ).ToList().ForEach( i => d.Add( i ) );
4844.2771 ms for the following code foreach ( string i in nv ) d.Add( i, nv[ i ] );

@robconery robconery closed this Jun 20, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment