[Mono-dev] Trivial Enumerable Optimizations
Jonathan Pryor
jonpryor at vt.edu
Thu May 8 15:36:17 EDT 2008
System.Core.Enumerable already has a set of "obvious" optimizations in
which the IEnumerable<T> argument is checked to see if it's another
interface and the implementation is "switched" based on the runtime
type, e.g.
public static bool Contains<TSource> (this IEnumerable<TSource> source, TSource value)
{
var collection = source as ICollection<TSource>;
if (collection != null)
return collection.Contains (value);
return Contains<TSource> (source, value, null);
}
Not all such optimizations were performed everywhere they could be --
I've found two, included in the attached System.Core-opt.diff patch.
The changes are noticeable (surprisingly to me); eo.cs contains my test
app. N is the number of iterations to do in the test, S is the size of
the array:
N,S 1.9[Long] Opt[Long] | 1.9[Rev] Opt[Rev]
--- ---------- ---------- | -------- --------
1,1: 00.0127820 00.0074890 | 00.0029850 00.0013530
1,1000:
10,10: 00.0103430 00.0067620 | 00.0031240 00.0013250
1000,1000: 00.0168560 00.0070100 | 00.0100230 00.0015060
10000000,1: 01.0322690 00.1243650 | 03.4776960 00.7064270
10000000,1000: 98.7992270 00.1945420 | 66.5775810 01.1917510
I wasn't expecting 1 iteration of an array with 1 element to actually
provide a noticeable improvement; perhaps something else is in play.
The change is quite noticeable at larger iterations.
Permission to commit?
- Jon
-------------- next part --------------
A non-text attachment was scrubbed...
Name: System.Core-opt.diff
Type: text/x-patch
Size: 2357 bytes
Desc: not available
Url : http://lists.ximian.com/pipermail/mono-devel-list/attachments/20080508/3f7b8fdb/attachment.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: eo.cs
Type: text/x-csharp
Size: 783 bytes
Desc: not available
Url : http://lists.ximian.com/pipermail/mono-devel-list/attachments/20080508/3f7b8fdb/attachment-0001.bin
More information about the Mono-devel-list
mailing list