Performance of float.CompareTo

Hi good people, I’ll go straight to the point. C# script.
I was sorting a List like this:

mColliders.Sort( (a, b) => ((a.Up.x-a.Radius).CompareTo(b.Up.x-b.Radius)));

and the performance on a ~250 long list were horrible, both in the editor and on the iPhone, roughly 3ms.

Then, just to test, I rewrote it with a dumb lamda like this:

mColliders.Sort( (a, b) => {
				if (a.Up.x-a.Radius>b.Up.x-b.Radius) return 1;
				else if (a.Up.x-a.Radius<b.Up.x-b.Radius) return -1;
				else return 0;
                });

Much better, went down to ~0.6ms.
Does anybody here have an idea of why the CompareTo was being so damn slow?

Thanks!

float.CompareTo is mostly likely converting a float value type into an object and then converting back to a value type. This boxing and unboxing process is slow, possibly worse in the iPhone .NET implementation.